A private method is a method that is used as an implementation part, not a [public] part of an interface. In other languages, where public and private methods are more efficient, private methods usually cannot be called by anything other than the class in which they are contained. The purpose of this is to hide implementation details or prevent external dependency on implementation details. For example, NSArray probably has a number of private methods that deal with memory allocation and optimized storage for efficient access.
Objective-C has no truly private methods; You can send any message you want for free, and it can respond to it, or maybe not. At run time, you can also check exactly which messages the class (and its instances) will respond through a series of calls to the Objective-C Runtime API [which are publicly documented].
Some people try to use private methods to obtain program behavior, which is not possible with a publicly documented interface; perhaps as an optimization, perhaps to do something that the API was never going to do. This is easily possible due to the dynamic nature of Objective-C and the lack of true private methods.
As a side note; Apple typically uses leading underscores in method names to indicate that it is private. Apple also states that method names beginning with an underscore are reserved for Apple only.
dreamlax Jun 09 '10 at 13:16 2010-06-09 13:16
source share