According to Apple's Objective-C specification, all unmarked instance variables are @protected
. I have found no information to say which directive is the default for methods; are they @protected
, @private
, or @public
?

- 63,694
- 13
- 151
- 195

- 975
- 2
- 7
- 17
-
Why don't you try it out? It should be easy enough to create a class and a subclass and see what the default behavior is. Also, since it isn't documented it could change in the future so beware of that. – David Rönnqvist Oct 04 '12 at 18:04
-
closely related: [Protected methods in ObjC](http://stackoverflow.com/questions/3725857/protected-methods-in-objective-c) – jscs Oct 04 '12 at 18:37
2 Answers
Those specifications have no applicability to methods. Methods work quite differently from ivars in ObjC. Specifically, one does not actually call a method. One sends a message. The object then interprets the message and takes some action. The usual action is to run the method that has the same name as the sent message, but there are other options.* Another common one is to throw an exception because the object can't figure out what else it should do with the message. This dispatch step is fundamental to ObjC, and it means that methods cannot truly be private.
Any message can be sent to any object,** and thus any method that exists on an object can be run at runtime.
It is possible to declare pseudo-private methods in class extensions or categories, such that a particular translation unit doesn't see it. Then you'll get a compiler warning or error when you try to send the corresponding message, but it's still possible (via performSelector:
and variants, or using objc_msgSend()
directly), to run the "private" method.
*Such as those presented in the Runtime Programming Guide under Dynamic Method Resolution and Message Forwarding.
**With the caveat that, when compiling under ARC and using the bracket syntax, [obj message]
, the compiler has to have seen a declaration of a method with that name for an object of that type, but that's another question.

- 63,694
- 13
- 151
- 195
All methods and all instance variables can be access from everywhere (with KVC), there is no real private. But the compiler will give you a warning if you try to send a message (call a method) that is not in the interface of your object. So all the methods in the @interface are public, and the others are private. About your instance variables, they are no more needed. Use properties instead.

- 1,718
- 11
- 15