Why can't my delegate execute the function SelectorOnMainThread: withObject: waitUntilDone :?

Xcode 4 gives me compiler warnings in a performSelectorOnMainThread:withObject:waitUntilDone: sent to my delegate, and I don't understand it.

My delegate is declared as follows:

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

And then it eventually runs along the main thread:

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

However, Xcode does not give me:

warning: Semantic Issue: Method '-performSelectorOnMainThread: withObject: waitUntilDone:' not found (the default return type is 'id')

Of course, the code compiles and works fine, but I don't like this warning. When I override the delegate as follows, the warning disappears, but I don't like the workaround:

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

What am I missing? What have I done wrong? Cheers
EP

+6
source share
1 answer

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

So you really have to declare your delegate as NSObject <AccountFeedbackDelegate> .

PS: The "standard" way to get rid of such a warning by declaring the protocol as @protocol AccountFeedbackDelegate <NSObject> will not work here because performSelectorOnMainThread:withObject:waitUntilDone: not declared in the NSObject protocol.

+19
source

Source: https://habr.com/ru/post/885998/


All Articles