• 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: Anything like -[performBlockOnMainThread:]?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Anything like -[performBlockOnMainThread:]?


  • Subject: Re: Anything like -[performBlockOnMainThread:]?
  • From: Thomas Davie <email@hidden>
  • Date: Mon, 15 Mar 2010 22:43:32 +0000

Just for reference's sake:

@interface NSObject (BlockOnMainThread)

- (void)performBlockOnMainThread:(void(^block)());

@end

@interface NSObject (BlockOnMainThreadPrivate)

- (void)performBlock:(void(^block)());

@end

@implementation NSObject (BlockOnMainThread)

- (void)performBlockOnMainThread:(void(^block)())
{
    [self performSelector:(performBlock:) withObject:[block copy] waitUntilDone:YES];
}

- (void)performBlock:(void(^block)())
{
    block();
    [block release];
}

@end

Note though, this was typed entirely into my email client, so YMMV.

Bob

On 15 Mar 2010, at 22:01, Keith Duncan wrote:

>
> On 15 Mar 2010, at 21:47, Rick Mann wrote:
>
>> Then again, what I was doing before was really:
>>
>> [mTarget performSelectorOnMainThread: mSelector withObejct: data waitUntilDone: true];
>
> In which case:
>
> NSBlockOperation *blockOperation = [NSBlockOperation blockOperationWithBlock:^ {
> 	...
> }];
> [[NSOperationQueue mainQueue] addOperation:blockOperation];
> [blockOperation waitUntilFinished];
>
> or
>
> dispatch_sync(dispatch_get_main_queue(), ^ {
> 	...
> });
>
>
> Keith
>
> _______________________________________________
>
> 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

_______________________________________________

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: 
 >Anything like -[performBlockOnMainThread:]? (From: Rick Mann <email@hidden>)
 >Re: Anything like -[performBlockOnMainThread:]? (From: Clark Cox <email@hidden>)
 >Re: Anything like -[performBlockOnMainThread:]? (From: Rick Mann <email@hidden>)
 >Re: Anything like -[performBlockOnMainThread:]? (From: Clark Cox <email@hidden>)
 >Re: Anything like -[performBlockOnMainThread:]? (From: Rick Mann <email@hidden>)
 >Re: Anything like -[performBlockOnMainThread:]? (From: Keith Duncan <email@hidden>)

  • Prev by Date: Re: Private ivars, not marked as IBOutlet, visible in IB
  • Next by Date: Re: Private ivars, not marked as IBOutlet, visible in IB
  • Previous by thread: Re: Anything like -[performBlockOnMainThread:]?
  • Next by thread: Re: Anything like -[performBlockOnMainThread:]?
  • Index(es):
    • Date
    • Thread