This is my simple piece of code on iOS, using ARC:
@interface Person : NSObject {
NSObject *objStrong;
NSObject *objWeek;
}
@property(strong) NSObject *objStrong;
//getting error at this line
@property(weak) NSObject *objWeek; //Existing ivar 'objWeek' for _week property 'objWeek' must be _week
@end
@implementation Person
@synthesize objStrong;
@synthesize objWeek;
@end
When I try to compile, the compiler complains about an existing ivar ‘objWeek’ for _weak property ‘objWeek’. Why isn’t this code compiling correctly?
It’s complaining because the backing variable,
NSObject *objWeekis declared as__strong(all otherwise unannotated Objective C pointers to retainable objects are__strong). Change the backing variable to be__weak NSObject *objWeek, and the compiler will like you again.Edit: As requested, the ARC documentation from LLVM’s clang:
Link: http://clang.llvm.org/docs/AutomaticReferenceCounting.html#ownership.inference