NSThread - 获取布尔值
我试图通过 NSThread 获取 -(BOOL)backupDropletUpdateAvailable
返回的布尔值。
为此,我尝试了以下操作:
` BOOL isAvailable = NO;
[NSThread detachNewThreadSelector:@selector(backupDropletUpdateAvailable) toTarget:isAvailable withObject:nil];
if (isAvailable == YES)
{//etc
它会返回一个警告,因为 BOOL 是一个整数,而 toTarget:
是一个指针。但我怎样才能得到这个值呢?如果我不在单独的线程上执行此操作,我的 xib 在出现时将会滞后。
谢谢 :)
I am trying to get the boolean value that's returned by -(BOOL)backupDropletUpdateAvailable
through NSThread.
To do this, I've tried the following:
` BOOL isAvailable = NO;
[NSThread detachNewThreadSelector:@selector(backupDropletUpdateAvailable) toTarget:isAvailable withObject:nil];
if (isAvailable == YES)
{//etc
Which returns a warning since BOOL is an integer and toTarget:
is a pointer. But how can I get the value? If I don't do this on a separate thread, my xib will lag when it appears.
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
线程运行的方法需要写入关心结果的对象可以访问的位置。一种解决方案是使用一个方法包装调用、获取结果并发布一条通知,其中将结果包含在用户信息中。然后关心的对象可以处理该通知。请注意,对象必须在线程启动之前创建,否则对象可能会错过通知。
解决方案的草图是:
The method run by the thread needs to write to a location that the objects that care about the result would have access to. One solution would be to have a method wrap the call, get the result, and post a notification that includes the result in the user info. Objects that care can then handle the notification. Note that the objects must be created before the thread is started, otherwise the object might miss the notification.
A sketch of the solution is: