Re: Safe to access the objectID property of an NSManagedObject from a different thread?
Re: Safe to access the objectID property of an NSManagedObject from a different thread?
- Subject: Re: Safe to access the objectID property of an NSManagedObject from a different thread?
- From: Mike Abdullah <email@hidden>
- Date: Sat, 26 Mar 2016 19:37:23 +0000
That's one of the few methods which are safe. I don't think the docs ever state it, but it was mentioned in a WWDC session a few years ago
Mike.
Sent from my iPhone
> On 26 Mar 2016, at 18:48, Ryan Meisters <email@hidden> wrote:
>
> Hi!
>
> I've inherited a codebase which uses MagicalRecord extensively. It seems that the recommended pattern for saving with MagicalRecord is something like this:
>
> [MagicalRecord saveWithBlock:^(NSManagedObjectContext *backgroundContext){
> Person *backgroundPerson = [mainThreadPerson MR_inContext:backgroundContext];
> backgroundPerson.firstName = @"John”;
> backgroundPerson.lastName = @"Appleseed";
> }];
>
> The MagicalRecord documentation states that the save block will always run on a background thread. So `mainThreadPerson`, which is captured from the surrounding scope is used from the backgrond thread to access the objectID.
>
> Is this ok? I believe the answer is no. The Core Data Programming Guide says:
>
> "NSManagedObject instances are not intended to be passed between queues. Doing so can result in corruption of the data and termination of the application. When it is necessary to hand off a managed object reference from one queue to another, it must be done through NSManagedObjectID instances."
>
> The author or this github issue https://github.com/magicalpanda/MagicalRecord/issues/448 raises the same concern. The basically says it's ok becuase "we're not accessing any Core Data properties at this point, we're accessing a ObjectID".
>
> Is this really ok?
>
>
> Kind Regards,
> Ryan
> _______________________________________________
>
> 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