将开发过程比较重要的代码做个珍藏,下面代码内容是关于睡眠排序法-objective C版的代码,应该能对各位朋友有帮助。
@interface NSArray (SleepSort)- (void)sleepSortObjectsUsingBlock:(void (^)(id obj))block;@end@implementation NSArray (SleepSort)- (void)sleepSortObjectsUsingBlock:(void (^)(id obj))block{ for (id obj in self) { [self performSelector:@selector(_handleSleepSortItemWithInfo:) withObject:info afterDelay:[obj intValue]]; }}{ id obj = [info objectForKey:@"obj"]; void (^block)(id obj) = [info objectForKey:@"block"]; block(obj);}@endTo use: [NSNumber numberWithInt:5], [NSNumber numberWithInt:3], [NSNumber numberWithInt:6], [NSNumber numberWithInt:3], [NSNumber numberWithInt:6], [NSNumber numberWithInt:3], [NSNumber numberWithInt:1], [NSNumber numberWithInt:4], [NSNumber numberWithInt:7], nil]; [items sleepSortObjectsUsingBlock:^(id obj) { NSLog(@"obj = %@", obj); }]; 复制代码