Skip to content

Instantly share code, notes, and snippets.

@wkiefer
Created August 9, 2010 02:18
Show Gist options
  • Save wkiefer/514835 to your computer and use it in GitHub Desktop.
Save wkiefer/514835 to your computer and use it in GitHub Desktop.
// This is why I love blocks.
// I have an async protocol to add/write a file to disk. Here's the full implementation of one call.
// It's so much easier than managing delegates, threads, callback objects and selectors.
- (void)addStoreItemWithType:(TAStoreItemType)type
identifier:(NSString *)identifier
properties:(NSDictionary *)properties
completionBlock:(void (^)(BOOL success, NSError *error))completionBlock {
dispatch_async(fileio_queue_,
^(void) {
NSError *error = nil;
BOOL success = [FileStore writeProperties:properties
toURL:[FileStore _urlForType:type identifier:identifier]
error:&error];
dispatch_async(dispatch_get_main_queue(), ^(void) { completionBlock(success, error); });
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment