简体   繁体   English

如何确定Apple方法是否异步?

[英]How can I determine if Apple methods are asynchronous?

I'm binding an NSArrayController to a managedObjectContext with mainQueueConcurrency. 我正在使用mainQueueConcurrency将NSArrayController绑定到managedObjectContext。

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. 我想做的就是用自己的函数修改arrangeObjects的排序属性,然后调用rearrangeObjects然后选择一些对象。

But it's looking like rearrangeObjects doesn't execute synchronously. 但它看起来像rearrangeObjects不同步执行。

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. 减去dispatch_async ,它不起作用。 The selection doesn't happen. 选择不会发生。

I'm fairly convinced that like fetch on an NSArrayController, rearrangeObjects is scheduling itself on the next runloop iteration. 我相信像在NSArrayController上fetch一样, rearrangeObjects会在下一次runloop迭代中调度自己。 ** 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" ?? 但是有一些调试技巧会让它显而易见“Eureka!这行代码启动异步操作”??

** It was cocoa bindings that's doing something asynchronously. **正在做异步的可可绑定。 Of course. 当然。 rearrangeObjects just triggers it. rearrangeObjects只是触发它。

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: 我能够通过在可疑的代码行之前断开并在GCD dispatch_async函数上启用符号断点来捕获rearrangeObjects调用dispatch_async_f (通过绑定)

dispatch_async上的符号断点*

And, sure enough, the dispatch_async_f symbolic breakpoint stopped on the rearrangeObjects line: 并且,果然, dispatch_async_f符号断点在rearrangeObjects行上停止:

在重排对象上激活断点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM