nsmanagedobjectcontext

Child context objects become empty after merge to parent/main context

大憨熊 提交于 2019-12-13 05:26:09
问题 I am working on a multi-threaded app using Core Data. Ironically, I thought the app was close to be finished when I learnt that Core Data was not thread safe... Hence, I'm now adding multi-context instead of the single-context that I got from the Xcode template (and has been working so far, really, but that's more luck than skill I guess) I'm attempting to use the > iOS 5.0 approach with parent/child contexts which would fit well with what I'm trying to do, but when I insert valid objects

How to rollback changes on temporary context?

天大地大妈咪最大 提交于 2019-12-13 05:16:18
问题 I create a temporaryContext like this: let temporaryContext = NSManagedObjectContext(concurrencyType: .PrivateQueueConcurrencyType) temporaryContext.parentContext = Utility.managedObjectContext() temporaryContext.performBlockAndWait({ // .. here I have done some changes on temporaryContext let success = temporaryContext.save(nil) //GUI get updated, GUI use MAIN context }) I want to roll back changes, so I do this: temporaryContext.performBlockAndWait({ temporaryContext.rollback() let success

Trying to dynamically create an NSManagedObject subclass based on NSString value in iOS

有些话、适合烂在心里 提交于 2019-12-13 05:07:36
问题 I am building an application that utilizes Core Data, which has multiple entities in the Data Model. What I would like to do is create a method which is able to create the appropriate subclass of NSManagedObject based on the name that the method it receives, which would be an NSString. My method looks like this: - (NSManagedObject *) addEntity:(NSString *)name { NSManagedObjectContext *context = [self managedObjectContext]; NSError *error; //need to add a line here that casts EntityType to of

Check for multiple nil values in Core Data managedObject?

对着背影说爱祢 提交于 2019-12-13 02:58:47
问题 I need to check if there any nil values in my managedObjectContext before saving them. At the minute I am doing tests on each key using if statements. I have many attributes in my NGLS entity, so as you can see testing each key for nil values doesn't seem very practical. if ([_managedObjectNGLS valueForKey:@"q1"] == nil){ [_managedObjectNGLS setValue:@"" forKey:@"q1"]; } if ([_managedObjectNGLS valueForKey:@"q1More"] == nil){ [_managedObjectNGLS setValue:@"" forKey:@"q1More"]; } .... // Save

Error when declaring NSManagedObjectContext

你说的曾经没有我的故事 提交于 2019-12-12 23:14:04
问题 I'm trying to create a NSManagedObjectContext object. They error reads as follows: Expected specifier-qualifier-list before 'NSManagedObjectContext' and here is my header file: #import <UIKit/UIKit.h> @interface FavouritesViewController : UITableViewController { NSArray *favourites; NSManagedObjectContext *context; } @property (nonatomic, retain) NSArray *favourites; @property (nonatomic, retain) NSManagedObjectContext *context; @end Anyone know I might be missing here? 回答1: Most probably you

How to set a relationship from one NSManageObject to another in a different NSManagedObjectContext

岁酱吖の 提交于 2019-12-12 22:42:14
问题 Because my app is multi-threaded I use two NSManagedObjectContexts. The main context, that runs in the main thread and another context that only runs in a separate thread. I have created a small test app. It has two Core Data Entities. Parent and Child. Parent has a one-to-many relationship to Child. Child has a 1-1 relationship to Parent. In one test method (that runs in a separate thread) I get a Parent instance, that has been created during a run time before. So it's in the main context. I

NSOperation in iOS - How to handle loops and nested NSOperation call to get Images

蹲街弑〆低调 提交于 2019-12-12 20:08:09
问题 I need help understanding how to appropriate handle the following use case: Say I'm writing a Chat app: Launch App Ask server ( AFHTTPRequestOperation ) to give me a list of all new messages Loop through those messages to see if I need to download any images If yes, then make another call to the server ( AFImageRequestOperation ) to get the image I keep getting crashes where my managed object "message" is no longer in the same context, but I'm only using one managedObjectContext . Is it

Why are Core Data NSManagedObject faults fired upon deletion?

不羁岁月 提交于 2019-12-12 14:31:30
问题 I'm trying to efficiently batch delete a lot of NSManagedObject s (without using an NSBatchDeleteRequest ). I have been following the general procedure in this answer (adapted to Swift), by batching an operation which requests objects, deletes, saves and then resets the context. My fetch request sets includesPropertyValues to false . However, when this runs, at the point where each object is deleted from the context, the fault is fired. Adding logging as follows: // Fetch one object without

How to assign a managed object context to the application delegate in iOS?

早过忘川 提交于 2019-12-12 09:26:43
问题 I created an iOS project and a managed object model ( Model.xcdatamodeld ) with one entity. In application:didFinishLaunchingWithOptions: I want to test if the managed object model exists, however I am getting nil . Do I have to do something special to create the managed object context after I create the managed object model? Any suggestions on what I may be doing wrong? This is the interface @interface AppDelegate : UIResponder <UIApplicationDelegate> { } @property (nonatomic, strong,

what's the 'proper' way to use NSManagedObjectContext's objectWithID:

送分小仙女□ 提交于 2019-12-12 08:09:24
问题 the docs state: ...This method always returns an object. The data in the persistent store represented by objectID is assumed to exist—if it does not, the returned object throws an exception when you access any property (that is, when the fault is fired). The benefit of this behavior is that it allows you to create and use faults, then create the underlying rows later or in a separate context. and in Apple's 'Core Recipes' sample app the result of the method is used to populate an