天天看點

Objective-C之Private peoperty

Do all @propertys have to be public? No. It is possible to declare a “private interface” to your class inside your implementation file.

Example (this is all in MyObject’s .m file):

@interface MyObject()

@property double myEyesOnly;

@end

@implementation MyObject

@synthesize eye, myEyesOnly;

@end

@interface MyObject()

This is the “magic” to declare your private stuff. You can put properties and methods here, but not more instance variables.

The property myEyesOnly can only be set/get via self.myEyesOnly since it is private.

The property myEyesOnly can only be set/get via self.myEyesOnly since it is private.