On 1/27/12 12:14 PM, Jens Alfke wrote: > I'm really used to using -performSelector:withObject:afterDelay: to > make something happen later. But I'd much rather use a block than a > target/action. I can't find any API for this, however. Am I missing > something? What I want is basically like PerformBlockAfterDelay(^{ > …code here…}, 5.0);
Take a look dispatch_after(). The main downside I have found to using this is that there is no (direct) analog to cancelPerformSelector. Most the idioms I have seen involve having the block check a variable (i.e. "BOOL stop") to determine whether they should continue executing. An alternative technique is a category on NSObject that has perform:/cancelPerform: methods accepting block arguments but using performSelector: internally to fire the block (or cancel firing). Mike Ash has a blog post that touches on this approach (http://www.mikeash.com/pyblog/friday-qa-2009-08-14-practical-blocks.html). -- Conrad Shultz Synthetiq Solutions www.synthetiqsolutions.com _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com