【发布时间】:2015-04-13 09:24:45
【问题描述】:
从我看到的所有代码中,几乎总是使用类似这样的方式来定义属性范围:
类扩展
/*We declare the class extension*/
@interface MyClass ()
@property (nonatomic, retain) Type *aPrivateProperty;
- (void)aPrivateMethod;
@end
/*
We can use the main implementation block to implement our properties
and methods declared in the class extension.
*/
@implementation MyClass
/*Therefore we can use synthesize ;-)*/
@synthesize aPrivateProperty;
- (void)aPrivateMethod {
//Some code there
}
@end
但这(据我所见)很少使用:
@interface MyClass : NSObject {
iVar *aProtectedIVar;
@public
iVar *aPublicIVar;
iVar *aSecondPublicIVar;
@protected
iVar *aSecondProtectedIVar;
@private
iVar *aPrivateIVAr;
}
@end
如果 @private、@protected 和 @public 等修饰符可用,为什么它们在 Objective-C 中没有被大量使用?
【问题讨论】:
标签: objective-c class properties scope ivar