How can I determine if Apple methods are asynchronous?

老子叫甜甜 提交于 2019-12-17 06:51:38

问题


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.


回答1:


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:



来源:https://stackoverflow.com/questions/23773827/how-can-i-determine-if-apple-methods-are-asynchronous

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!