关于客观c属性设置器如何工作的问题

ody*_*yth 0 iphone properties objective-c

我对属性的两个假设是否正确?

@interface Foo : NSObject {
NSDate *Created;
}

@property (nonatomic, retain) NSDate *Created;

@end

@implementation Foo

@synthesize Created;

- (id) init {
if(self = [super init])
{
    Created = [NSDate date]; //this will not call the setter and instead just access the variable directly, which means it will not automatically get retained for me.
    self.Created = [NSDate date]; // this will call the setter, which will retain the variable automatically for me.
}
return self;
}

- (void)dealloc {
    [Created release]   
    [super dealloc];
}
@end
Run Code Online (Sandbox Code Playgroud)

bbu*_*bum 7

是; 那是正确的.

请注意,实例变量应该是created; 它应该以小写字母开头.我也推荐creationDate.