Just for my curiousity, I am trying to rewrite the following code
// show HUD (with animation)
[SVProgressHUD showWithStatus:@"loading..."];
// wait for HUD to safely finish showing its animation
// (loading HUD will be visible for 1 sec)
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]
// dismiss HUD
// (dismiss HUD will be visible for 2 sec)
[SVProgressHUD dismissWithSuccess:@"finished!" afterDelay:2];
into the code using Grand Central Dispatch.
I tried using dispatch_source_t, dispatch_semaphore_t, and dispatch_after,
but doesn’t quite work well:( and I need your help!
Please note that I don’t want to wrap SVProgressHUD’s methods with any blocks!
You really can’t. Or, you could, but it’d be a ton of work that would ultimately just wrap the
NSRunLoopstuff itself.Within the context of iOS and Mac OS X, the main event loop is a run loop and things like modal panels, HUDs, and the like are all designed around that detail.
The code you are showing is a nested run loop. You are effectively running the main run loop in a sub-loop within an outer loop that is also maintained by the main run loop! (If you were to set a breakpoint on an action method fired within your internal loop, you would see what I mean in the backtrace).