Reputation: 3928
It is casually mentioned here that instance variables have __strong
enabled per default - does this mean that having this:
@interface Foo {
Bar *test; // implicitly __strong
}
@property (nonatomic, unsafe_unretained) Bar *test;
@end
and calling
test = [[Bar alloc] init];
in the implementation file, that the new Bar
instance will be retained? If yes, will the Bar
instance be released at all when Foo is deallocated, considering that the property tells ARC to not touch it?
Upvotes: 1
Views: 1134
Reputation: 64002
Did you try compiling that? It won't work. The ivar associated with a property has to have the same ownership qualifier as the property. This is in the Clang ARC doc:
If the associated instance variable already exists, then its ownership qualification must equal the ownership of the property; otherwise, the instance variable is created with that ownership qualification.
@interface Digby : NSObject
{
NSString * wiska;
}
@property (unsafe_unretained) NSString * wiska;
@end
@implementation Digby
@synthesize wiska; // Existing ivar 'wiska' for property 'wiska' with unsafe_unretained attribute must be __unsafe_unretained
@end
If you remove the explicit ivar declaration, then the synthesized ivar will be __unsafe_unretained
, like the property.
Upvotes: 2