如何确定Apple方法是否是异步的? [英] How can I determine if Apple methods are asynchronous?

查看:127
本文介绍了如何确定Apple方法是否是异步的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用mainQueueConcurrency将NSArrayController绑定到managedObjectContext。



我想要的是使用自己的函数修改sortedObjects的排序属性,然后调用 rearrangeObjects 然后选择一些对象。



但它看起来像 rearrangeObjects 不能同步执行。



那么我如何证明这种方式呢?



这样做:

  [self.myArrayController rearrangeObjects]; 

// Async需要 - 我相信重新调用一个fetch,这是async
dispatch_async(dispatch_get_main_queue(),^ {
[self.myArrayController setSelectedObjects:anArray];
});

减少 dispatch_async 工作。选择不会发生。



我相信像NSArrayController上的 fetch rearrangeObjects 是在下一个runloop迭代上调度自己。 **那么我如何证明呢?我可以在那里抛出断点并检查数组控制器等等。我有,我怀疑是发生了什么。



但是有一些调试技巧使它变得明显Eureka!这行代码启动一个异步操作



**这是可异步绑定,是异步做。当然。

我可以捕获 rearrangeObjects 调用通过在可疑代码行之前断开并在GCD dispatch_async函数上启用符号断点,可以通过 dispatch_async_f (通过绑定)
$ b



而且, rearrangeObjects 行上的 dispatch_async_f 符号断点停止:




I'm binding an NSArrayController to a managedObjectContext with mainQueueConcurrency.

All that I want is to do is modify the sort properties the arrangedObjects with my own function and then call rearrangeObjects and then select some objects.

But it's looking like rearrangeObjects doesn't execute synchronously.

So how can I prove that, one way or the other?

This works:

[self.myArrayController rearrangeObjects];

// Async needed -- I believe rearrange calls a fetch, which is async
dispatch_async(dispatch_get_main_queue(), ^{
    [self.myArrayController setSelectedObjects:anArray];
});

Minus the dispatch_async, it doesn't work. The selection doesn't happen.

I'm fairly convinced that like fetch on an NSArrayController, rearrangeObjects is scheduling itself on the next runloop iteration.** So how do I prove that? I can throw breakpoints in there and examine the array controller, etc etc. And I have, and I suspect that's what's happening.

But is there some debugging trick which would just make it obvious "Eureka! This line of code's launching an asynchronous operation" ??

** It was cocoa bindings that's doing something asynchronously. Of course. rearrangeObjects just triggers it.

解决方案

I was able to catch rearrangeObjects invoking dispatch_async_f (through bindings) by breaking just before the suspect line of code and enabling symbolic breakpoints on the GCD dispatch_async functions:

And, sure enough, the dispatch_async_f symbolic breakpoint stopped on the rearrangeObjects line:

这篇关于如何确定Apple方法是否是异步的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆