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 (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