Alex Rivera | Logout

How to make properties private?

Asked 2011-08-09T14:53:06.210
10

Someone told me I could make properties private so that only an instance of the class can refer to them (via self.)

However, if I use @private in the class interface and then declare the property normally, it can still be accessed from outside of the class... So how can I make properties private? Syntax example please.

Edit
Report

1 Answer

5

Declare the property in the implementation (.m) file, like so:

@interface MyClass()

@property (nonatomic, retain) MyPrivateClass *secretProperty;

@end

You'll be able to use that property within your class without a compiler warning.

answered 2011-08-09T14:58:06.770

Your Answer