简体   繁体   中英

How can I determine if Apple methods are asynchronous?

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:

dispatch_async上的符号断点*

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

在重排对象上激活断点

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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