6

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

epologee
  • 11,229
  • 11
  • 68
  • 104

1 Answers1

19

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.

Ole Begemann
  • 135,006
  • 31
  • 278
  • 256
  • 1
    Thanks for that one @Ole, that indeed explains it. I'll keep declaring the delegate with id, but cast it to NSObject before calling the `performSelectorOnMainThread:withObject:waitUntilDone:` method. – epologee Apr 15 '11 at 15:41
  • 1
    NSObject *propertyName – cynistersix Dec 19 '12 at 19:34