Protected methods in Objective-C

You can simulate protected and private access to methods by doing the following:

  • Declare your private methods in a class extension (i.e. a unnamed category declared near the top of the class’ .m file)
  • Declare your protected methods in a Subclass header – Apple uses this pattern with respect to UIGestureRecognizer (see documentation and reference to UIGestureRecognizerSubclass.h)

These protections are not, as Sachin noted, enforced at runtime (as they are in Java, for example).

Leave a Comment