开发者

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

This question already has answers here: Compiler gives warning on performSelectorOnMainThread:@selector(delegateMethod) (4 answers) Closed 10 years ago.

Xcode 4 is giving me compiler warnings on the performSelectorOnMainThread:withObje开发者_StackOverflow社区ct: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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜