我正在学习Objective C语言,我问一个简单的问题, 当我做到这一点:属性公共和私人但不受保护?
// ParentClass.h
@interface ParentClass : NSObject
@property (read, strong) NSString *parentPublicStr;
@end
// ParentClass.m
@interface ParentClass()
@property (readwrite, strong) NSString *parentPrivateStr;
@end
@implementation ParentClass
@synthesize parentPublicStr;
@synthesize parentPrivateStr;
@end
// Subclass SubClass.h
@interface SubClass : ParentClass
- (void) test;
@end
@implementation SubClass
- (void) test
{
// Its not possible to do that : [self setParentPrivateStr:@"myStrin"]
// And for parentPublicStr, it is public property so not protected, because i can change the value
// in main.c, and it's so bad..
}
@end
我想创建一个受保护的属性:X
THX你。 (对不起,我的英语)
[Objective-C - Private vs Protected vs Public]可能的重复(http://stackoverflow.com/questions/4869935/objective-c-private-vs-protected-vs-public) –