Objective-C之Private peoperty

来源:互联网 发布:mac大型游戏推荐 编辑:程序博客网 时间:2024/04/28 11:55

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.