iOS developers have a "dispatch_after(when, queue, block)" Grand Central Dispatch (GCD) function they can utilize but once it's set up, these calls can not be easily cancelled. Describe how you might implement a more convenient version of this named "cancellable_dispatch_after"
Sigiloso
If we create an object called BoolNumber, e.g.: class BoolNumber : NSObject { @property (readwrite) Bool boolValue; } We can return it from our cancellable_dispatch_after method like so: - (BoolNumber *) cancellable_dispatch_after(when, queue, block) { BoolNumber *cancelState = [[BoolNumber alloc] init]; // the newBlock only runs after "when" and only if the cancelState bool value is set to false newBlock = ^{ if ( cancelState.boolValue == NO) block() }; dispatch_after(when, queue, newBlock); return cancelState; } So anybody calling this API will have a BoolNumber object which can cancel the block from running anytime during the "when" waiting period.