Reputation: 6174
For example, if I have a property index
and an ivar _index
, is it at all slower to use self.index
, [self index]
and [self setIndex:]
?
Upvotes: 2
Views: 225
Reputation: 5558
Using the accessors impose an overhead, a method call at the very least.
That said, guesses and proofs are different things. The overhead may be great, or not. In any case, profiling the application will show where the CPU time is spent and what should be optimized. I seriously doubt using accessors over direct ivars will impact any application to the point accessors should be avoided.
Atomic and copy properties will be much much slower, these choices will have a greater impact and should be considered more carefully. Use them when appropriate.
But the answer is in profiling your app.
Edit:
Accessors have many benefits : encapsulation, code consistency between clients, derived classes and the class itself, overriding, debugging property accesses when needed, read only access checks... plenty of good reasons to pay a small performance price. All good reasons aren't always good enough tho. ;)
If accessors become a problem, I would say an Objective-C class may not be the appropriate choice for the job. A C++ class have more opportunities to be fast : non-virtual methods, inline methods, stack based instances...
Upvotes: 4