开发者

Do variables assigned to properties follow the behavior of that property?

Looking f开发者_开发技巧or a little clarification on how Objective-C properties work when 'linked' to instance variables. My confusion stems from how you can set a property equal to a instance variable through the @synthesize directive, like...

@synthesize someProp = _someIVar;

Now, if my someProp is all like...

@property (retain,readonly) SomeClass* someProp

...will this...

-(id)initWithAutoreleasedInstanceOfSomeClass:(SomeClass*)thingThatIsAutoreleased {
    self = [super init];
    if(self) {
         _someIVar = thingThatIsAutoreleased;
    }
    return self;
}

... cause thingThatIsAutoreleased to be retained?

Tanks!


since it's readonly you won't have a setter but you can set the value by setting the internal member variable. If you set the internal var, then you need to retain it.

_someIVar = [thingy retain];

Note that you can call via KVC and get the retain to trigger

[self setValue:myValue forKey:@"someProp"];

So, to answer your original question, No, you won't get automatic retain/release if you're setting the iVar directly. You have to retain/release if you're manipulating the iVar.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜