nsmanagedobjectcontext

Save NSUndoManager transactions one by one

廉价感情. 提交于 2019-12-25 04:29:19
问题 I need to save changes not only locally into Core Data , but on server too. My concern is, in my case user can do bunch of interaction in a short time. Between interaction there is not enough time to receive success message returned from server. So either I lock the GUI, until next message returns - this is the case now -, or choose a different approach. My new approach would be to let user do many interactions and put transactions onto undo stack provided by NSUndoManager , enabled on

Issues handing over managedObjectContext

与世无争的帅哥 提交于 2019-12-25 01:39:16
问题 I have been reading up most questions on this item, but somehow I can't figure this one out. I managed easily to hand over the ManagedObjectContext from the AppDelegate to the first view in previous applications I tried, where the initial viewController handled also the data. Now in a new application I am building, I need an initial screen where the user needs to make a selection (through a few possible buttons). On this screen my MOC is still intact as per my troubleshooting (the NSLog

undo all changes made in a view controller

99封情书 提交于 2019-12-25 00:23:20
问题 Is it possible to undo all changes made in a view controller without affecting the changes made in its parent view controller? btw. They are with the same managedObjectContext. ps. I have two entities A and B. A has an to-many relationships to B. View controller VCA is used to perform some changes in A. View controller VCB is used to perform some changes in B. VCA is the parent view controller of VCB. 回答1: No need to create a new context. When you leave the child view controller, you have the

NSmanaged context threads

半城伤御伤魂 提交于 2019-12-24 17:40:50
问题 I use a singleton for working with arrays etc. cross the views in the application. To initialize the singleton and the NSManagedObjectContext , so that I can fetch objects, I use: +(DataControllerSingleton *)singleDataController { static DataControllerSingleton * single=nil; @synchronized(self) { if(!single) { single = [[DataControllerSingleton alloc] init]; NSManagedObjectContext *context = [single.fetchedResultsController managedObjectContext]; single.masterCareList = [[NSMutableArray alloc

NSManagedObject values are correct, then incorrect when merging changes from parent to child NSManagedObjectContext

不问归期 提交于 2019-12-24 13:16:06
问题 I’m having a Core Data issue while using 2 NSManagedObjectContext , running on different threads, and migrating changes from the parent to the child. In essence, I’m able to pull the changes from parent to child, but immediately after doing so, the changes are lost. The app I’m building is a test for syncing a model between multiple devices and a server. The context that holds the objects the user interacts with is on the main thread and is configured as a child of the sync context and is

Objective C best way to see how many times a method is called

[亡魂溺海] 提交于 2019-12-24 08:28:06
问题 I want to determine how many times a particular method is called on NSManagedObject. What are anybody's suggestions for the best way of doing this? Bearing in mind that i have 30+ managed objects and I don't want to change the superclass of all of them. Thanks 回答1: -(void) method { static int callCount = 0; callCount++; /* method body */ } 回答2: Create an alternate method in a category that tracks the number of calls in a static variable and the swizzle the method with the original

How should I guarantee fetch results from a different thread in a nested contexts are up to date, when saves are done asynchronously in background?

混江龙づ霸主 提交于 2019-12-24 07:42:06
问题 I've read the following Behavior differences between performBlock: and performBlockAndWait:? But wasn't able to find an answer to my question. The following code is picked up from an RayWenderlich video. Specifically at 10:05 the code is something like this: class CoreDataStack { var coordinator : NSPersistentStoreCoordinator init(coordinator: NSPersistentStoreCoordinator){ self.coordinator = coordinator } // private, parent, in background used for saving private lazy var savingContext :

'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name

落爺英雄遲暮 提交于 2019-12-23 23:58:43
问题 I have a window based applicaiton with tab bar and navigation bar integrated into it. On the navigation bar have a custom button which opens a table view. On clicking on the cell of the table I want to open a new table view controller. But as soon as I click on the cell of first table I get an exception that Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'AddForm'' I have checked

Add an instance of NSManagedObject to NSManagedObjectContext ok, updating the same instance failed

孤人 提交于 2019-12-23 12:29:25
问题 I am using core data in my iPhone app. I have created a simple class Friend , which derives from NSManagedObject and which uses the following property: @property (nonatomic, retain) NSString *name; I am able to add and delete instances of this class to my context and my changes are persistent also. Now I want to update/modify a Friend -instance and make it persistent again. But this seems not to work. Here is piece of code which shows my problem: // NSManagedObjectContext *context = < my

Strange parent / child NSManagedObjectContext phenomenon

本秂侑毒 提交于 2019-12-23 07:27:17
问题 I have created two context like this: // create writer MOC _privateWriterContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; [_privateWriterContext setPersistentStoreCoordinator:_persistentStoreCoordinator]; // create main thread MOC _managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; _managedObjectContext.parentContext = _privateWriterContext; I have a NSFetchResultedController initiated