Skip to content

Instantly share code, notes, and snippets.

@jnjosh
Created May 1, 2012 20:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnjosh/2571191 to your computer and use it in GitHub Desktop.
Save jnjosh/2571191 to your computer and use it in GitHub Desktop.
//
// NSMutableArray+TTAdditions.h
// tester
//
// Created by Joshua Johnson on 5/1/12.
// Copyright (c) 2012 Two Toasters, LLC. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSMutableArray (TTAdditions)
/** Sort Mutable Array using an NSComparator with a completion handler
*
* @param comparator an NSComparator block for comparing results
* @param handler a completion handler to perform when the sort is complete
*/
- (void)tt_sortUsingComparator:(NSComparator)comparator withCompletionHandler:(void (^)(void))handler;
@end
//
// NSMutableArray+TTAdditions.m
// tester
//
// Created by Joshua Johnson on 5/1/12.
// Copyright (c) 2012 Two Toasters, LLC. All rights reserved.
//
#import "NSMutableArray+TTAdditions.h"
static dispatch_queue_t sort_queue = NULL;
@implementation NSMutableArray (TTAdditions)
- (void)tt_sortUsingComparator:(NSComparator)comparator withCompletionHandler:(void (^)(void))handler
{
if (sort_queue == NULL) {
sort_queue = dispatch_queue_create("com.twotoasters.additions.sorting", 0);
}
dispatch_async(sort_queue, ^{
[self sortUsingComparator:comparator];
if (handler) {
dispatch_async(dispatch_get_main_queue(), ^{
handler();
});
}
});
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment