Skip to content

Instantly share code, notes, and snippets.

@Phillipus
Last active August 13, 2016 17:08
Show Gist options
  • Select an option

  • Save Phillipus/6537635 to your computer and use it in GitHub Desktop.

Select an option

Save Phillipus/6537635 to your computer and use it in GitHub Desktop.

Revisions

  1. Phillipus renamed this gist Sep 12, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Phillipus created this gist Sep 12, 2013.
    17 changes: 17 additions & 0 deletions gistfile1.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    // Macro - Set the flag for block completion
    #define StartBlock() __block BOOL waitingForBlock = YES

    // Macro - Set the flag to stop the loop
    #define EndBlock() waitingForBlock = NO

    // Macro - Wait and loop until flag is set
    #define WaitUntilBlockCompletes() WaitWhile(waitingForBlock)

    // Macro - Wait for condition to be NO/false in blocks and asynchronous calls
    // Each test should have its own instance of a BOOL condition because of non-thread safe operations
    #define WaitWhile(condition) \
    do { \
    while(condition) { \
    [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; \
    } \
    } while(0)