What does -> mean?

前端 未结 5 915
太阳男子
太阳男子 2021-01-12 13:03

I\'m a relative newbie to Objective-C (only studied Arron Hillegras\'s book) and am confused by the following snippit of code I\'ve found in one of Apple\'s code examples, i

5条回答
  •  伪装坚强ぢ
    2021-01-12 13:53

    You use -> when you want to access an ivar. Like C structures you will use a . or -> (in pointers to structs) in Objective-C objects you can use -> but is not necessary since you can access them directly.

    Hence:

    self->_numbers = [numbers copy];
    

    and

    _numbers = [numbers copy];
    

    are the same

    You want to use -> when you want to access that ivar explicitly.

    Be aware that in Objective-C you can use . but only when its a property. You can use -> regardless that.

提交回复
热议问题