>> 
> 
> performBlockAndWait might work. In my completion handler I have basically:
> 
> Context = [self createPrivateContect];
> 
> For (I = 1; I < something ; i++)
> {
>    ...do stuff with completetion data from URL...
> 
>    ...do stuff with the context...
> 
> }
> 
> So I need to make sure the context stuff finishes before the for loop goes
> onto the next pass through the loop.
> 
> 
> 

What’s wrong with 

        for( i - i ; i < something ; i++ )
        {
                moc.performBlock( { 
                        … do stuff with completion data
                        .. block which does stuff with the context
                } )
        }

nothing says you can only have MOC work in the block

or even

        moc.performBlock(       
        {
                for( i - i ; i < something ; i++ )
                {
                        … do stuff with completion data
                        .. do stuff with the context
                } 
        } )

Which is basically your original code just in a performBlock on the MOC’s 
private thread. 


There are other ways too where, if you want to perform the first load of work 
on one thread and the MOC stuff on the MOC thread, you can do that by putting 
one iteration in a method or creating a local block which does one iteration 
with work on one queue, then sends the MOC stuff to the private queue, at the 
end of the work on the MOC you increment i and if you have another one to do, 
enqueue the whole thing back on the first thread again. 

        int __block i = 1;

        void (^myBlock)() = { 
                .. do stuff with completion data
                moc.performBlock( {
                        .. do stuff with the context
                        if( i++ < something )
                                dispatch_async( myOtherQueue, myBlock );
                }
        }

        myBlock()

I’m sure there’s lots more. You can use performBlockAndWait but rarely need to. 

All examples typed in mail and I’ve not been using objc for a while so may have 
my (^) in the wrong place. 




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to