nsmanagedobject

Filling an array with core data attributes

左心房为你撑大大i 提交于 2019-12-13 18:26:09
问题 I'm trying to fill my array. var weights = [] with attributes from an NSManaged object. My core data relationship is like follows Client<-->>Assessment. I have a 'weight' attribute within assessment and I would like to fill my array with these values which are strings. My variable: var client: Client! = nil successfully retrieves the specific client that I have selected, but I do not know how to fill my array with the values of that particular client's assessment attribute called 'weight'. I

Core Data: How to update an NSArrayController immediately after adding an NSManagedObject?

匆匆过客 提交于 2019-12-13 07:36:08
问题 I am adding an instance in core data. The entity is represented by an NSArrayController . I would like to access the newly added instance through the controller. A "Skill" instance is added and then I try to access it through selectAddedObject as follows: -(void)addSkill { [self selectAddedObject:[NSEntityDescription insertNewObjectForEntityForName:@"Skill" inManagedObjectContext:self.managedObjectContext]]; } - (void)selectAddedObject:(NSManagedObject *)addedMO { [self.sectionArrayController

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

SWIFT CoreData NSManagedObject

吃可爱长大的小学妹 提交于 2019-12-13 05:13:57
问题 I have a Custom NSManagedObject (in Swift) and looks like this import UIKit import CoreData @objc(Item) class Item: NSManagedObject { @NSManaged var title:String func entityName() -> String{ println("Entity Name") let item = "Item" return item } func insertItemWithTitle (title: String? , managedObjectContext:NSManagedObjectContext) -> Item{ println(title) let item = NSEntityDescription.insertNewObjectForEntityForName(entityName(), inManagedObjectContext: managedObjectContext) as Item if title

Weird Core Data Reaction - Not Detecting NSManagedObject Sub Classes

丶灬走出姿态 提交于 2019-12-13 05:13:25
问题 There seems to be a very weird bug in my app in which I'm using Core Data . I handled everything required already, and it was working for like past recent weeks. I closed the project yesterday, and started development today ( with no modifications in code ) and now every time I wanna add a row to my database, I get an exception saying the following class is not a subclass of NSManagedObject , which I'm ridiculously sure is not true, first because it was working for days, and second because I

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

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

NSPersistentStoreCoordinator throws EXC_BAD_ACCESS when deallocating an NSManagedObject after reading a specific NSManagedProperty

假装没事ソ 提交于 2019-12-12 20:03:16
问题 Error Description I have an app with some data stored locally using core data (backed by SQLite) and the following NSManagedObject subclass import CoreData @objc(ScoutingEventData) class ScoutingEventData: NSManagedObject { @NSManaged var id: String? @NSManaged var type: String? @NSManaged var entityId: String? @NSManaged var oldStateJson: NSData? @NSManaged var newStateJson: NSData? @NSManaged var eventDate: NSDate? func toInsertEvent() throws -> ScoutingEvent.Insert { guard let id = id else