You didn't post any code, leaving us to infer what you're doing. I'm going to assume it's something like this:
@interface ViewController ()
@property id someProperty; // This works
@private
id someVar; // This does not work
@end
and:
@implementation ModelClass
{
@property id someProperty; // This does not work
@private
id someVar; // This works
}
@end
Assuming that's true, it seems you're confused about the nature of properties vs. instance variables. @property is essentially a way to declare accessor methods, for which the compiler (by default) automatically synthesizes method implementations and a corresponding backing instance variable. Instance variables on the other hand, are simply per-instance variables, not methods at all.
The first block of code above is a class extension on ViewController
. Class extensions allow you to declare additional methods -- and thereby @properties too -- separately from the main/public interface for a class.
The braces after @implementation
in the second block denote a place to declare additional instance variables (only).
@protected
and @private
are visibility modifiers for instance variable declarations, and control whether an instance variable is visible only to instances of the class itself (@private
), instances of the class and its subclasses (@protected
), or publicly (@public
). These modifiers cannot be used for methods (of which @properties are a special case). Afterall, in Objective-C, methods are actually always public in the sense that it's only at runtime that a message send is turned into a method call, and the compiler can't truly enforce a limitation on calls to "private" methods.
Finally, to answer what I think is the heart of your question, you most certainly can add a class extension to your model class in order to declare additional "private" @properties and other methods. Xcode may not include one in the default new file template for non-view controllers, but that doesn't mean you can't add one yourself:
@interface ModelClass ()
@property id somePrivateProperty; // Works just fine
@end