What does this symbol -> mean?
Now I am a little confused after seeing a piece of code for the iPhone SDK that uses -> instead of dot notation. It is very similar to PHP, but it works on iPhone. Can someone explain that to → , this is what I need to know about the deep C-secret?
Example:
- (void)setFileURLs: (NSArray*)elements {
if (self->fileURLs != elements)
fileURLs is an instance variable or property, for example:
@property(nonatomic, retain) NSArray *fileURLs;
and there @synthesize for url files. Now I think this is the case: because this is a setter method for file servers, it would be bad to use dot notation to access an instance variable. In fact, when I do this, the application crashes. This is because it calls itself over and over again, as the dot notation refers to the accessor, not the ivar directly. But -> will refer to ivar directly.
If that's correct, the question will change a little: why write "self-> fileURLs" and not just "fileURLs"? What's the point of adding this homing in front of him? Does this make sense? Why?
See the "Other Operators" section at:
http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B
Since it self
is a pointer, you should use ->
, not .
to access its members. Turning a link self
into fileURLs
is most likely the coding style used by the author (which is equivalent to writing this.member
).
source to share