I have the following code (where an error appears):
.h file
#import <Foundation/Foundation.h>
@interface Unit : NSObject
{
UIImageView *view;
CGRect rect;
}
@property(readonly, assign) UIImageView *view;
@property(readwrite, assign) CGRect rect;
@end
.m file
#import "Unit.h"
@implementation Unit
@synthesize view; //Error appears here
@synthesize rect;
@end
The error that appears is existing ivar 'view' for unsafe_unretained property 'view' must be __unsafe_unretained. What does this mean and how can I fix it?
In your example, you have used (readonly, assign), however because you have also explicitly created the ivar, you need to add the
__unsafe_unretainedqualifier (due to assign qualifier) as per Automatic Reference Counting documentation on property declarations.Simply remove the ivar declaration, and the compiler will generate the correct ownership qualifier.