• 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: Clark Cox <email@hidden>
  • Date: Mon, 15 Mar 2010 14:51:30 -0700

You could do:

NSOperation *op = [NSBlockOperation blockOperationWithBlock: ^{
    ...
}];
[NSOperationQueue mainQueue] addOperations: [NSArray arrayWithObject:
op] waitUntilFinished: YES]

or:

dispatch_sync(dispatch_get_main_queue(), ^{
    ...
});

but be very careful that you aren't already running on the main
thread, as you could deadlock.

On Mon, Mar 15, 2010 at 2:47 PM, Rick Mann <email@hidden> wrote:
> Then again, what I was doing before was really:
>
> [mTarget performSelectorOnMainThread: mSelector withObejct: data waitUntilDone: true];
>
> which I don't see how to do with 1[addOperationWithBlock:];
>
> On Mar 15, 2010, at 14:46:28, Clark Cox wrote:
>
>> Indeed, such is the power of blocks :)
>>
>> On Mon, Mar 15, 2010 at 2:45 PM, Rick Mann <email@hidden> wrote:
>>> Oh! Sorry for the noise, but I think I can do this:
>>>
>>> [[NSOperationQueue mainQueue] addOperationWithBlock: ^{
>>>   myProvidedBlock(param1, param2);
>>> }];
>>>
>>>
>>> On Mar 15, 2010, at 14:35:39, Clark Cox wrote:
>>>
>>>> On Mon, Mar 15, 2010 at 2:32 PM, Rick Mann <email@hidden> wrote:
>>>>> Instead of passing my operation a target and selector, is there any way I can just pass it a block, but then have it execute that block on the main thread?
>>>>
>>>> [[NSOperationQueue mainQueue] addOperationWithBlock: ^{
>>>>    ...
>>>> }];
>>>>
>>>> or:
>>>>
>>>> dispatch_async(dispatch_get_main_queue(), ^{
>>>>    ...
>>>> });
>>>>
>>>>
>>>> --
>>>> Clark S. Cox III
>>>> email@hidden
>>>
>>>
>>
>>
>>
>> --
>> Clark S. Cox III
>> email@hidden
>
>



--
Clark S. Cox III
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

  • Follow-Ups:
    • Re: Anything like -[performBlockOnMainThread:]?
      • From: Benjamin Rister <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>)

  • Prev by Date: Re: Anything like -[performBlockOnMainThread:]?
  • Next by Date: Re: Anything like -[performBlockOnMainThread:]?
  • Previous by thread: Re: Anything like -[performBlockOnMainThread:]?
  • Next by thread: Re: Anything like -[performBlockOnMainThread:]?
  • Index(es):
    • Date
    • Thread