为什么我的委托不接受performSelectorOnMainThread:withObject:waitUntilDone:?

发布于 2024-11-01 23:07:59 字数 744 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

提赋 2024-11-08 23:07:59

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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文