Dispatch_async somewhere behind, can not find. is there an NSLog problem?

So, I have this code:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{

//Bunch of code

NSLog(@"Test");

});

which starts and immediately returns nslog. But the code results appear only on the screen in a few seconds of delay. Is there a problem using nslog here, which means that it was called earlier than usual, which makes it fast when it really is. I am confused as to where this delay comes from, since the NSLog is right at the end of all the code that is being executed then.

Also, another solution to my problem - can I get an NSLog when each method is called (something like NSZombiesEnabled, I suppose), so I can make sure there is no bit that I did not notice, my application’s sweet response time?

+5
3

. , - , . : ( ). , , , , ... , , , - .

, , :

dispatch_async(dispatch_get_main_queue(), ^{
        // Do GUI stuff.
    });

, , , . :

dispatch_async(dispatch_get_main_queue(), ^{
        [self.somewidget setNeedsDisplay];
        [self.view setNeedsDisplay];
        [self.dontforgetme setNeedsDisplay];
    });

, , , GDC, . , , GUI , :

/// Stick this in code you want to assert if run on the main UI thread.
#define DONT_BLOCK_UI() \
    NSAssert(![NSThread isMainThread], @"Don't block the UI thread please!")

/// Stick this in code you want to assert if run on a background thread.
#define BLOCK_UI() \
    NSAssert([NSThread isMainThread], @"You aren't running in the UI thread!")

, , , , . https://github.com/gradha/ELHASO-iOS-snippets, .

+11

UIKit . , , , , , . :

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    // Background code that doesn't need to update the UI here

    dispatch_async(dispatch_get_main_queue(), ^{
        // UI code here
    });
});
+11

Instead of using // Bundles of code, you must insert real code, otherwise it is difficult to find your problem and spend our time. I think you are likely to update ui in the "code bundle", which should be in the main thread.

-1
source

All Articles