I have seen both ways from different programmers.
- [[self object] method]
- [object method]
Some other just use [self.object method] instead of [[self object] method].
Does self give me a safety about not calling other objects ?
I think second way is more readable.
What should I use ?
It’s up to you. They are just different styles of programming. However, if your getter method does more than just return
object, callingself.objector[self object](which are the same thing) every time could be less efficient.for example:
consider these two examples:
vs.
The second method could be more efficient, since the “random code” in the getter method is only executed once, whereas in the first example it is executed twice (each time
[self object]is called).