objective-c开发问题~新手
黄舟
黄舟 2017-04-24 09:11:31
0
3
461
- (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这一块 求指教!谢谢!

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(3)
伊谢尔伦

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

cvoid setTire(Tire tire,int index){
    tires[index]=tire;
}
Tire setTire(int index){
    return tires[index];
}

or JAVA

javapublic void setTire(Tire tire,int index){
    tires[index]=tire;
}
public Tire tireAtIndex(int index){
    return tires[index];
}

apple new language swift

swiftfunc setTire(tire:Tire,index:Int){
    tires[index]=tire;
}
func tireAtIndex(index:Int)->Tire{
    return tires[index];
}

JS with Arrow Function

javascriptvar setTire=(tire,index)=>tires[index]=tire;
var tireAtIndex=(index)=>tires[index];
迷茫

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template