nsmanagedobjectcontext

Core Data not saving transformable NSMutableDictionary

寵の児 提交于 2019-11-30 21:54:41
I have two classes: Profile and Config. A Profile contains an NSSet of Config objects. Both Profile and Config are NSManagedObject subclasses. @interface Profile : NSManagedObject @property (nonatomic, retain) NSString * name; @property (nonatomic, retain) NSSet *configs; - (void)print; @end Here is the Config class @interface Config : NSManagedObject @property (nonatomic, retain) NSString * otherdata; @property (nonatomic, retain) NSString * name; @property (nonatomic, retain) NSMutableDictionary *myDict; @property (nonatomic, retain) Profile *profile; - (void)print; @end The dictionary

NSManagedObjectContext save doesn't crash but breaks on objc_exception_throw

倖福魔咒の 提交于 2019-11-30 21:18:40
I am having the same issue described at this address http://www.cocoabuilder.com/archive/cocoa/288659-iphone-nsmanagedobjectcontext-save-doesn-crash-but-breaks-on-objc-exception-throw.html I am debugging an application that uses Core Data with multithreading, and I have a breakpoint on objc_exception_throw and it hits this breakpoint in the call to save. (line 2 in code) NSError *error = nil; [self.managedObjectContext save:&error]; if (error) { NSLog(@"Error : %@",error); } I don't have any thing that is logged. I am using Xcode 4 with ios 4.0 -> 4.3. I think this is not related to Xcode/iOS

How to handle cleanup of external data when deleting *unsaved* Core Data objects?

谁都会走 提交于 2019-11-30 20:21:50
In a managed object i have stored a path to an image file in the application's container. When the managed object get’s deleted, the image file should be moved to trash. This should be done as late as possible, so that i can provide undo functionality for as long as possible. I was following the answers of this question: How to handle cleanup of external data when deleting Core Data objects , and was overriding -didSave in my managed object subclass to trash the files. Turns out, this works only if: the managed object has been added, the managed object context has been saved , the managed

Core-Data executeFetchRequest freezes App in a background thread

Deadly 提交于 2019-11-30 18:11:22
问题 I have a saveMOC which is the direct parent of a mainMOC , and I need for online fetch another tmpMOC in order not to block my UI whilst fetching a ton of records from the Internet. My app freezes. I could narrow it to this very point: fetchedItems = [tmpMOC executeFetchRequest:fetchRequest error:&error]; I tried to enclose this within dispatch_sync , [moc.parentcontext.parentcontext.persistentStoreCoordinator lock/unlock] , [whatevermoc performBlockAndWait] ... I also try to fetch the

Performing multiplication (aggregation) with CoreData: how to?

两盒软妹~` 提交于 2019-11-30 17:50:09
问题 Following a fantastic tutorial by Jeff Lamarche, I'm trying to aggregate data for a specific subclass of NSManagedObject . This is the scenario. I created a class named Product that extends NSManagedObject class. Product class has three properties like the following: @property (nonatomic, retain) NSString* name; @property (nonatomic, retain) NSNumber* quantity; @property (nonatomic, retain) NSNumber* price; I also created a category, called Product+Aggregate , where I perform a sum

Core data multithreading fetch record

本小妞迷上赌 提交于 2019-11-30 16:26:44
I have one doubt about multithreading in coredata. if we are using multithreading we should use separate NSManagedObjectContext for inserting new data or updating or else we can use parent child context method. But i am creating new NSManagedObjectContext only. My question is that should i use separate NSManagedObjectContext for even fetching in background thread also. If not (i.e. we can use main queue NSManagedObjectContext only) than why i m getting __psynch_mutexwait error. Thanks, First, Core Data is thread safe. However you must follow the rules: NSManagedObjectContext is thread bound.

Core Data: parent context blocks child

给你一囗甜甜゛ 提交于 2019-11-30 15:14:22
I'm doing some background processing in an app with core data. The background processing is done on a child managedObjectContext. Context initialization: appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate // the moc in appDelegate is created with .MainQueueConcurrencyType mainThreadMOC = appDelegate.managedObjectContext! backgroundMOC = NSManagedObjectContext(concurrencyType:NSManagedObjectContextConcurrencyType.PrivateQueueConcurrencyType) backgroundMOC?.parentContext = mainThreadMOC Background processing is done in the following method: // download all new transaction

Core data find-or-create most efficient way

点点圈 提交于 2019-11-30 12:59:40
I have around 10000 objects of entity ' Message '. When I add a new ' Message ' i want to first see whether it exists - and if it does just update it's data, but if it doesn't to create it. Right now the "find-or-create" algorithm works with by saving all of the Message objects ' objectID ' in one array and then filtering through them and getting the messages with existingObjectWithID:error: This works fine but in my case when I fetch an 'Message' using existingObjectWithID : and then try to set and save a property by setting the property of the 'Message' object and calling save: on it's

undo all changes made in the child view controller

99封情书 提交于 2019-11-30 12:33:25
问题 There are two entities: Author and Book. Author has an attribute authorName and a to-many relationships books. Book has several attributes and a relationship author. There is a view controller (VCAuthor) to edit an Author object. The child view controller(VCBook) is to edit books of the author. There is only one managedobjectcontext. In the VCBook class i group the undomanager as following -(void)viewDidLoad { NSUndoManager *anUndoManager = [[NSUndoManager alloc] init]; [self.book

what's the difference between NSManagedObjectContext reset and rollback?

拈花ヽ惹草 提交于 2019-11-30 11:03:38
The documentation says: - (void)reset Returns the receiver to its base state. Discussion All the receiver's managed objects are “forgotten.” If you use this method, you should ensure that you also discard references to any managed objects fetched using the receiver, since they will be invalid afterwards. - (void)rollback Removes everything from the undo stack, discards all insertions and deletions, and restores updated objects to their last committed values. Discussion This method does not refetch data from the persistent store or stores. It seems that after I make some change to my context,