sophtwhere

NSObject+arcAgnostics.m

Nov 1st, 2013
71
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  NSObject+arcAgnostics.m
  3. //
  4. //  Created by Jonathan Annett on 1/11/13.
  5. //  Copyright (c) 2013 Sophtwhere. All rights reserved.
  6. //
  7.  
  8. #import "NSObject+arcAgnostics.h"
  9.  
  10.  
  11. typedef void(^MyCustomBlock)(NSObject*thing);
  12.  
  13. typedef BOOL(^MyCustomBlock2)(NSObject*thing);
  14.  
  15. @implementation NSObject (arcAgnostics)
  16.  
  17. -(id)  __SELF__{
  18.     return self;
  19. }
  20.  
  21. -(void)  __NOP__ {
  22.     // literally do nothing. (NOP = NO OPERATION)
  23. }
  24.  
  25.  
  26.  
  27. +(void) test {
  28.    
  29.    
  30.     static NSDictionary *mydict;
  31.     @autoreleasepool {
  32.         mydict = @{ @"key" : @"user"};
  33.     }
  34.    
  35.     NSLog(@"hello %@",mydict[@"key"]);
  36.    
  37.     dispatch_block_t greeting = ^{
  38.         NSLog(@"hello");
  39.     };
  40.    
  41.    
  42.     MyCustomBlock greeting2 = ^(NSObject *thing){
  43.         NSLog(@"hello %@",thing);
  44.     };
  45.    
  46.     MyCustomBlock2 greeting3 = ^BOOL(NSObject *salutation){
  47.         NSLog(@"%@ multiverse(s)",salutation);
  48.         return YES;
  49.     };
  50.    
  51.    
  52.     greeting();
  53.    
  54.    
  55.    
  56.     dispatch_block_t deferred_greeting = Block_copy(greeting);
  57.    
  58.     MyCustomBlock deferred_greeting2 = Block_copy(greeting2);
  59.    
  60.     MyCustomBlock2 deferred_greeting3 = Block_copy(greeting3);
  61.    
  62.     double delayInSeconds = 2.0;
  63.     dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
  64.     dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
  65.         deferred_greeting();
  66.         deferred_greeting2(@"universe");
  67.         if(deferred_greeting3(@"howdie")) {
  68.             NSLog(@"so long and thanks for all the fish");
  69.         };
  70.        
  71.         Block_release(deferred_greeting);
  72.         Block_release(deferred_greeting2);
  73.         Block_release(deferred_greeting3);
  74.     });
  75.    
  76.    
  77. }
  78.  
  79. @end
RAW Paste Data