-(void)setTire:(Tire*)tireatIndex:(int)index{[tiresreplaceObjectAtIndex:indexwithObject:tire];}//setTire:atIndex:-(Tire*)tireAtIndex:(int)index{Tire*tire;tire=[tiresobjectAtIndex:index];return(tire);}//tireAtIndex:这是objective-c基础教程里面的代码我就是不理解这段什么意思尤其是(Tire*)tireAtIndex:(int)index这一块求指教!谢谢!
2 回答
ITMISS
TA贡献1871条经验 获得超8个赞
就是个数组的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];
有只小跳蛙
TA贡献1824条经验 获得超8个赞
我也很困惑为啥有人这样写代码。而且还是教程,这不是误导新手吗不是啥SetterGetter方法,就是普通的两个方法,方法的功能就是类似设置数组的某项的object,和获取某项的object
添加回答
举报
0/150
提交
取消