objective-c开发问题~新手

-(void)setTire:(Tire*)tire
atIndex:(int)index
{
[tiresreplaceObjectAtIndex:index
withObject:tire];
}//setTire:atIndex:
-(Tire*)tireAtIndex:(int)index
{
Tire*tire;
tire=[tiresobjectAtIndex:index];
return(tire);
}//tireAtIndex:
这是objective-c基础教程里面的代码
我就是不理解这段什么意思尤其是(Tire*)tireAtIndex:(int)index这一块求指教!谢谢!
慕田峪9158850
浏览 559回答 2
2回答

ITMISS

就是个数组的setter/getter,只不过OC的语法就这样写,用其他语法写出来你应该能看清楚了。相当于C语言的这种写法cvoidsetTire(Tiretire,intindex){tires[index]=tire;}TiresetTire(intindex){returntires[index];}或者JAVAjavapublicvoidsetTire(Tiretire,intindex){tires[index]=tire;}publicTiretireAtIndex(intindex){returntires[index];}apple新语言swiftswiftfuncsetTire(tire:Tire,index:Int){tires[index]=tire;}functireAtIndex(index:Int)->Tire{returntires[index];}JSwithArrowFunctionjavascriptvarsetTire=(tire,index)=>tires[index]=tire;vartireAtIndex=(index)=>tires[index];

有只小跳蛙

我也很困惑为啥有人这样写代码。而且还是教程,这不是误导新手吗不是啥SetterGetter方法,就是普通的两个方法,方法的功能就是类似设置数组的某项的object,和获取某项的object
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript