hide @property in objective C
How to hide @property(retain, nonatomic)NSString*str in some 开发者_运维知识库class?
If you want to hide it from being visible in the .h file, consider using a private class extension in the .m file:
@interface YourClass ()
@property(retain, nonatomic)NSString*str;
@end
You can use a feature called “categories,” which allows you to extend an existing class by adding properties and methods to it.
Typically, you use an empty category inside your class's .m file for private methods and properties, and define a separate named category in an external .h file for protected members. Categories are actually quite interesting in that they allow you to override existing properties. So, for example, you can define a property as read-only in your .h file:
@interface Whatever {
NSObject *aValue;
}
@property (nonatomic,retain,readonly) NSObject *aValue;
@end
And then you can make it read/write for your own private use in an empty category inside your .m file:
@interface Whatever()
@property (nonatomic,retain) NSObject *aValue;
@end
You can find more about categories here.
精彩评论