Objective-C Tips & Trick - Prioregroup.com
[Objective-C] Threads Helper
       
back

NS_INLINE void OnMainThread(int64_t after_sec, dispatch_block_t block)
{
    if (!block)
        return;
    else if (after_sec > 0)
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(after_sec * NSEC_PER_SEC)), dispatch_get_main_queue(), block);
    else if ([NSThread isMainThread])
        block();
    else
        dispatch_async(dispatch_get_main_queue(), block);
}

NS_INLINE void OnNewThread(long priority, int64_t after_sec, dispatch_block_t block)
{
    if (!block)
        return;
    else if (after_sec > 0)
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(after_sec * NSEC_PER_SEC)), dispatch_get_global_queue(priority, 0), block);
    else if (![NSThread isMainThread])
        block();
    else
        dispatch_async(dispatch_get_global_queue(priority, 0), block);
}






Copyright © 1996-2018 Centro Studi Informatica di Danilo Priore. All rights reserved. P.I.10149810581.
prioregroup.com