• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to get the dispatch queue for the current thread's runloop?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >How to get the dispatch queue for the current thread's runloop? (From: Jens Alfke <email@hidden>)
 >Re: How to get the dispatch queue for the current thread's runloop? (From: Steve Sisak <email@hidden>)

  • Prev by Date: Re: Full-Height Toolbar Item
  • Next by Date: Re: Blocks and Methods...
  • Previous by thread: Re: How to get the dispatch queue for the current thread's runloop?
  • Next by thread: Re: How to get the dispatch queue for the current thread's runloop?
  • Index(es):
    • Date
    • Thread