Re: Anything like -[performBlockOnMainThread:]?
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