__weak and __unsafe_unretained property #31

Closed
obaidjawad opened this Issue Apr 10, 2012 · 3 comments

Comments

Projects
None yet
2 participants

First I got this error
"existing ivar '_messageDelegate' for unsafe_unretained property '_messageDelegate' must be __unsafe_unretained"

When I declared as

__weak NSObject *_chatDelegate;

@property (nonatomic, assign) id _chatDelegate;

So I replace __weak with __unsafe_unretained because I'm using the xcode 4.2 with ARC enabled project. Then the errors went off.

Then later when I used the _chatDelegate in the below code I got this error Receiver type 'NSObject' for instance message does not declare a method with selector 'newMessageReceived' Which is an ARC issue.

if (![presenceFromUser isEqualToString:myUsername]) {

if ([presenceType isEqualToString:@"available"]) {

[_chatDelegate newBuddyOnline:[NSString stringWithFormat:@"%@@%@", presenceFromUser, @"obaid.local"]];

//error in this line as Receiver type 'NSObject' for instance message does not declare a method with selector 'newMessageReceived' Which is an ARC issue.

} else if ([presenceType isEqualToString:@"unavailable"]) {

[_chatDelegate buddyWentOffline:[NSString stringWithFormat:@"%@@%@", presenceFromUser, @"obaid.local"]];

}

}

Please help me with this issue.

Owner

robbiehanson commented Apr 10, 2012

What file is this in?

This is in my Appdelegate class. However I solved it by replacing the assign return type with the weak return type for the property. And for the other error I had to use the Delegate return type while declaring the *_chatDelegate; so I replace it with
__weak NSObject < SMChatDelegate > *_chatDelegate; so, it is now good to go! :)

I forgot to say Thank you for your valuable response to my issue Robbiehanson.

@obaidjawad obaidjawad closed this Apr 11, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment