if you don't want it accessible to other classes, declare the @property on your implementation, creating an anonymous category for your class.
Header file:
// MyClass.h
@interface MyClass : NSObject {
NSObject *_privateObject;
NSObject *_readonlyObject;
NSObject *_publicObject;
}
@property (nonatomic, retain, readonly) NSObject *readonlyObject;
@property (nonatomic, retain) NSObject *publicObject;
@end
Implementation:
// MyClass.m
@interface MyClass ()
@property (nonatomic, retain) NSObject *privateObject;
// Make it writable on the implementation
@property (nonatomic, retain, readwrite) NSObject *readonlyObject;
@end
@implementation MyClass
@synthesize privateObject = _privateObject;
@synthesize readonlyObject = _readonlyObject;
@synthesize publicObject = _publicObject;
These are examples of three different properties.
- privateObject is not visible on other classes;
- readonlyObject is visible but is read only;
- publicObject is visible and can be get and set;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…