Re: How to get the dispatch queue for the current thread's runloop?
Re: How to get the dispatch queue for the current thread's runloop?
- Subject: Re: How to get the dispatch queue for the current thread's runloop?
- From: Steve Sisak <email@hidden>
- Date: Sat, 28 Jan 2012 14:35:33 -0500
At 12:14 PM -0800 1/27/12, 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.
At 12:23 PM -0500 1/28/12, Steve Sisak wrote:
This reminds me that, IIRC, a block (after it's copied to the heap)
_is_ an object. I was going to suggest some form of calling
BlockCopy manually, but given the example above, you might something
like:
-(void)executeBlock:((^)(void) block // <- someone help with this declaration
{
block();
}
This was interesting enough to stick my head in the documentation and
build a test program.
The following appears to work:
- (void)performBlock:(void (^)(void)) block
{
block();
}
- (IBAction) doItNow:(id)sender
{
[self performSelector:@selector(performBlock:) withObject:^{
NSLog(@"Done");
}];
}
- (IBAction) doItLater:(id)sender
{
[self performSelector:@selector(performBlock:)
withObject:^{
NSLog(@"Done Later");
} afterDelay:1.0];
}
Does anyone see a problem with this technique?
-Steve
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden