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

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

问题描述

我正在使用 mainQueueConcurrency 将 NSArrayController 绑定到 managedObjectContext.

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

我想要做的就是用我自己的函数修改排列对象的排序属性,然后调用rearrangeObjects,然后选择一些对象.

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.

但看起来 rearrangeObjects 没有同步执行.

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

那么我如何证明这一点,以一种或另一种方式?

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

这有效:

[self.myArrayController rearrangeObjects];

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

减去 dispatch_async,它不起作用.选择不会发生.

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

我相当确信,就像 NSArrayController 上的 fetch 一样,rearrangeObjects 会在下一次运行循环迭代中自行调度.** 那么如何我能证明吗?我可以在那里设置断点并检查数组控制器等.我有,而且我怀疑这就是正在发生的事情.

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.

但是是否有一些调试技巧可以让Eureka!这行代码启动异步操作"显而易见??

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.

推荐答案

我能够通过在可疑行之前中断来捕获 rearrangeObjects 调用 dispatch_async_f(通过绑定)代码和在 GCD dispatch_async 函数上启用符号断点:

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:

而且,果然,dispatch_async_f 符号断点停在了 rearrangeObjects 行:

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

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

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