• 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: CoreData and insert in multithread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

re: CoreData and insert in multithread


  • Subject: re: CoreData and insert in multithread
  • From: Ben Trumbull <email@hidden>
  • Date: Wed, 30 Jan 2008 16:49:12 -0800

malcom,

There's no easy way to get Core Data to see unsaved data in another context (on another thread).

For non-inserted objects, you can replicate the changes in the other thread by passing a dictionary between the threads. Some methods that can help do this:

On NSManagedObject:

- (NSDictionary *)committedValuesForKeys:(NSArray *)keys; - (NSDictionary *)changedValues;

In KVC protocol generally:

-(NSDictionary *)dictionaryWithValuesForKeys:(NSArray *)keys;
- (void)setValuesForKeysWithDictionary:(NSDictionary *)keyedValues;

For inserted objects, you're SOL.

In general, though, it's better to just not have the problem. If the background thread makes a bunch of changes, save the batch, and pull (fetch/objectWithID:) them onto the main thread.

Most apps don't require synchronously forcing the main thread to update status from background threads in the middle of a task. Accepting a little bit of staleness in the UI, and having it refresh every few seconds, is usually acceptable.

If it's crucial, you can use proxies on the main thread, backed either by a managed object (for saved changes), or an NSDictionary (for unsaved changes).
--


-Ben
_______________________________________________

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


  • Prev by Date: Re: Best way to notify the Controller when one Array object value is changed
  • Next by Date: Re: reset alternating row background color
  • Previous by thread: Re: CoreData and insert in multithread
  • Next by thread: CoreData and NSOperation
  • Index(es):
    • Date
    • Thread