Created
October 6, 2012 06:36
-
-
Save bsneed/3844232 to your computer and use it in GitHub Desktop.
perform a block in a background thread, and call a completion block on the main thread when its done.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSObject+RFExtensions.h | |
// | |
// Created by brandon on 10/5/12. | |
// Copyright (c) 2012 redf.net. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
typedef void (^NSObjectPerformBlock)(id userObject); | |
@interface NSObject (RFExtensions) | |
- (void)performBlockInBackground:(NSObjectPerformBlock)performBlock completion:(NSObjectPerformBlock)completionBlock userObject:(id)userObject; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSObject+RFExtensions.m | |
// | |
// Created by brandon on 10/5/12. | |
// Copyright (c) 2012 redf.net. All rights reserved. | |
// | |
#import "NSObject+RFExtensions.h" | |
@implementation NSObject (RFExtensions) | |
- (void)performBlockInBackground:(NSObjectPerformBlock)performBlock completion:(NSObjectPerformBlock)completionBlock userObject:(id)userObject | |
{ | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | |
performBlock(userObject); | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
completionBlock(userObject); | |
}); | |
}); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment