daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest May 17th, 2018 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (void)viewDidLoad {
  2.     [super viewDidLoad];
  3.  
  4.     [self testGCD];
  5. }
  6.  
  7. - (void)testGCD {
  8.     static dispatch_once_t onceToken;
  9.     dispatch_once(&onceToken, ^{
  10.         NSLog(@"1");
  11.         return;
  12.     });
  13.     NSLog(@"2");
  14. }
  15.    
  16. - (void)testGCD {
  17.     static dispatch_queue_t queue = dispatch_queue_create("com.example.MyQueue", NULL);
  18.     static bool firstRun = YES;
  19.  
  20.     dispatch_sync(queue, ^{
  21.        if (firstRun) {
  22.            NSLog(@"1);
  23.            firstRun = NO;
  24.        } else {
  25.            NSLog(@"2");
  26.        }
  27.     });
  28. }
  29.    
  30. - (void)testGCD {
  31.     static BOOL didTrigger = NO;
  32.  
  33.     if(didTrigger) {
  34.         NSLog(@"2");
  35.     }
  36.     else {
  37.         didTrigger = YES;
  38.         NSLog(@"1");
  39.     }
  40. }
  41.    
  42. - (void)testGCD {
  43.     static dispatch_once_t onceToken;
  44.     static BOOL didInvokeOnceBlock = NO;
  45.     static BOOL didPassSkippedBlock = NO;
  46.     dispatch_once(&onceToken, ^{
  47.         NSLog(@"1");
  48.         didInvokeOnceBlock = YES;
  49.     });
  50.     if(didInvokeOnceBlock && didPassSkippedBlock) {
  51.         NSLog(@"2");
  52.     }
  53.     didPassSkippedBlock = YES;
  54. }
  55.    
  56. - (void)testGCD {
  57.     static dispatch_once_t onceToken;
  58.     __block NSString *text = @"2";
  59.     dispatch_once(&onceToken, ^{
  60.         text = @"1";
  61.     });
  62.     NSLog(@"%@", text);
  63. }
RAW Paste Data
Top