- (void) setTire: (Tire *) tire
atIndex: (int) index
{
[tires replaceObjectAtIndex: index
withObject: tire];
} // setTire:atIndex:
- (Tire *) tireAtIndex: (int) index
{
Tire *tire;
tire = [tires objectAtIndex: index];
return (tire);
} // tireAtIndex:
这是objective-c基础教程里面的代码
我就是不理解这段什么意思 尤其是(Tire *) tireAtIndex: (int) index这一块 求指教!谢谢!
It’s just an array setter/getter, but the syntax of OC is written like this. You should be able to see it clearly if written in other syntax.
This is equivalent to this writing method in C language
or JAVA
apple new language swift
JS with Arrow Function
I’m also confused as to why someone writes code like this. And it’s a tutorial. Isn’t this misleading to newbies? It’s not a Setter Getter method, it’s just two ordinary methods. The function of the method is similar to setting the object of a certain item in the array, and getting the object of a certain item
Now you no longer need to define instance variables and write access methods, just use properties directly!
The tutorials you are watching are probably from 3 years ago.
For tutorials on properties, you can visit our blog about the introduction of properties