Objective-C existing instance variable must be __unsafe_unretained error

cocoa, objective-c

Solution

The default ownership qualification for instance variables in ARC is `strong`, and like @robMayoff mentioned assign is the same as `unsafe_unretained` so your code reads like the following:

@interface webberAppDelegate : NSObject <NSApplicationDelegate> {
   __strong NSWindow *window;
   __strong WebView *webber;
}

@property (unsafe_unretained) IBOutlet NSWindow *window;
@property (unsafe_unretained) IBOutlet WebView *webber;

As mentioned in the linked answer provided by @Firoze, the property declaration and iVar should have matching ownership qualification. So the solution would be to make the `__strong` in the above code to `__unsafe_unretained` or to remove the instance variable declarations completely so that the compiler takes care of it.

The same solution is provided in the linked answer in the comment. Just adding some info.

Problem

Same code are already questionned here, but I deal with a different problem that I can't solve myself probably because i'm new with Objective-C, so I decide to ask the question :) webberAppDelegate.h: ``` #import <Cocoa/Cocoa.h> #import <WebKit/WebKit.h> @interface webberAppDelegate : NSObject <NSApplicationDelegate> { NSWindow *window; WebView *webber; } @property (assign) IBOutlet NSWindow *window; @property (assign) IBOutlet WebView *webber; @end ``` webberAppDelegate.m: ``` #import "webberAppDelegate.h" @implementation webberAppDelegate @synthesize window; @synthesize webber; - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { NSString *urlString = @"http://www.apple.com"; // Insert code here to initialize your application [[webber mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]]; } @end ``` So, in webberAppDelegate.m, here's my problem with this fraction I suppose: ``` @synthesize window; @synthesize webber; ``` who give me this long error: ``` Existing instance variable 'window' for property 'window' with assign attribute must be __unsafe_unretained ``` and pratically the same for other var "webber": ``` Existing instance variable 'webber' for property 'webber' with assign attribute must be __unsafe_unretained ``` Thanks for your help, I really appreciate Stackoverflow community for days !!

Original source

Related problems