为什么我的委托不接受performSelectorOnMainThread:withObject:waitUntilDone:?
Xcode 4 在发送给我的委托的 performSelectorOnMainThread:withObject:waitUntilDone:
消息上向我发出编译器警告,但我没有收到。
我的委托声明如下:
@property (nonatomic, assign) id <AccountFeedbackDelegate> delegate;
然后最终在主线程上执行:
[self.delegate performSelectorOnMainThread:@selector(didChangeCloudStatus) withObject:nil waitUntilDone:NO];
然而 Xcode 仍然坚持给我:
警告:语义问题:找不到方法“-performSelectorOnMainThread:withObject:waitUntilDone:”(返回类型默认为“id”)
当然,代码编译并运行良好,但我不喜欢这个警告。当我像这样重新声明委托时,警告消失了,但我不喜欢解决方法:
@property (nonatomic, assign) NSObject <AccountFeedbackDelegate> *delegate;
我错过了什么?我做错了什么? 干杯,
EP
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
performSelectorOnMainThread:withObject:waitUntilDone:
在 NSThread.h 的NSObject
上的类别中声明。由于您的变量是id
类型,编译器无法确定它是否可以响应为NSObject
定义的消息。与普通id
变量不同,当您的变量被声明为id
时,编译器会发出警告。因此,您确实应该将委托声明为
NSObject
。PS:通过将协议声明为 @protocol AccountFeedbackDelegate来消除此类警告的“标准”方法在这里不起作用,因为
performSelectorOnMainThread:withObject:waitUntilDone:< /code> 未在
NSObject
协议中声明。performSelectorOnMainThread:withObject:waitUntilDone:
is declared in a category onNSObject
in NSThread.h. Since your variable is of typeid
, the compiler cannot be certain that it can respond to a message defined forNSObject
. And unlike with plainid
variables, the compiler warns you about this when your variable is declaredid <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 becauseperformSelectorOnMainThread:withObject:waitUntilDone:
is not declared in theNSObject
protocol.