Looking for 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.
Note that you can call via KVC and get the retain to trigger
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.