Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why won't my delegate accept performSelectorOnMainThread:withObject:waitUntilDone:? [duplicate]

Xcode 4 is giving me compiler warnings on the performSelectorOnMainThread:withObject:waitUntilDone: message sent to my delegate and I don't get it.

My delegate is declared like:

@property (nonatomic, assign) id <AccountFeedbackDelegate> delegate;

And then eventually executed on the main thread:

[self.delegate performSelectorOnMainThread:@selector(didChangeCloudStatus) withObject:nil waitUntilDone:NO];

Yet Xcode persists on giving me:

warning: Semantic Issue: Method '-performSelectorOnMainThread:withObject:waitUntilDone:' not found (return type defaults to 'id')

Of course the code compiles and runs fine, but I don't like the warning. When I redeclare the delegate like this, the warning vanishes, but I don't like the workaround:

@property (nonatomic, assign) NSObject <AccountFeedbackDelegate> *delegate;

What am I missing? What did I do wrong? Cheers,
EP

like image 397
epologee Avatar asked Apr 15 '11 15:04

epologee


1 Answers

performSelectorOnMainThread:withObject:waitUntilDone: is declared in a category on NSObject in NSThread.h. Since your variable is of type id, the compiler cannot be certain that it can respond to a message defined for NSObject. And unlike with plain id variables, the compiler warns you about this when your variable is declared id <SomeProtocol>.

So you should indeed declare your delegate as NSObject <AccountFeedbackDelegate>.

PS: The "standard" way to get rid of this kind of warning by declaring the protocol as @protocol AccountFeedbackDelegate <NSObject> won't work here because performSelectorOnMainThread:withObject:waitUntilDone: is not declared in the NSObject protocol.

like image 95
Ole Begemann Avatar answered Oct 16 '22 20:10

Ole Begemann