Re: CoreData headaches
Re: CoreData headaches
- Subject: Re: CoreData headaches
- From: Chris Hanson <email@hidden>
- Date: Sun, 30 Oct 2016 12:16:45 -0700
On Oct 28, 2016, at 9:44 PM, Steve Mills <email@hidden> wrote:
>
> On Oct 27, 2016, at 23:35:39, Dave Fernandes <email@hidden> wrote:
>>
>> The managed objects exist in a MOC whether you have a reference to that MOC or not. You can get a reference to the MOC that an MO “belongs to" from the -[NSManagedObject managedObjectContext] instance method. Since the properties you need are so few and simple, why don’t you just pass these in to the NSOperation when you create it on the main thread instead of giving it the managed object? Then the MO will never be accessed off the main queue.
>
> I moved the CGImageSource creation to outside the block, which is where I needed to access the managed object's folder and name properties. The block now just loads the image from the source, converts it to an NSImage, and sets the managed object's thumb property. It's no longer crashing, but the setting of the thumb property seems like that shouldn't happen inside the block.
You’re correct in this, reading a property of an NSManagedObject from another thread isn’t safe, and writing it isn’t either.
> So would that be the right place to use the NSManagedObjectContext's performBlock:?
What you’ve done actually looks correct, in that you’re only interacting with the managed object’s managed (Core Data) properties (“thumb” in this case) within the block passed to -performBlock:.
-- Chris
_______________________________________________
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