Sleep sequencing objective version C

From , 2 Years ago, written in Objective-C, viewed 220 times.
URL https://pastebin.vip/view/7dd3ed2e
  1. @interface NSArray (SleepSort)
  2. - (void)sleepSortObjectsUsingBlock:(void (^)(id obj))block;
  3. @end
  4.  
  5. @implementation NSArray (SleepSort)
  6.  
  7. - (void)sleepSortObjectsUsingBlock:(void (^)(id obj))block
  8. {
  9.     for (id obj in self) {
  10.         NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:obj, @"obj", block, @"block", nil];
  11.         [self performSelector:@selector(_handleSleepSortItemWithInfo:) withObject:info afterDelay:[obj intValue]];
  12.     }
  13. }
  14.  
  15. - (void)_handleSleepSortItemWithInfo:(NSDictionary *)info
  16. {
  17.     id obj = [info objectForKey:@"obj"];
  18.     void (^block)(id obj) = [info objectForKey:@"block"];
  19.     block(obj);
  20. }
  21.  
  22. @end
  23.  
  24. To use:
  25.  
  26.  
  27.     NSArray *items = [NSArray arrayWithObjects:
  28.         [NSNumber numberWithInt:5],
  29.         [NSNumber numberWithInt:3],
  30.         [NSNumber numberWithInt:6],
  31.         [NSNumber numberWithInt:3],
  32.         [NSNumber numberWithInt:6],
  33.         [NSNumber numberWithInt:3],
  34.         [NSNumber numberWithInt:1],
  35.         [NSNumber numberWithInt:4],
  36.         [NSNumber numberWithInt:7],
  37.         nil];
  38.    
  39.     [items sleepSortObjectsUsingBlock:^(id obj) { NSLog(@"obj = %@", obj); }];
  40. //objectc/6503

Reply to "Sleep sequencing objective version C"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website