nsmanagedobject

MagicalRecord relationship mapping duplicates objects despite primary keys

不问归期 提交于 2019-12-04 12:31:51
问题 I'm in need of some assistance for an issue I am experiencing with MagicalRecord data importing. I was under the impression that MagicalRecord was able to handle relationship mapping without duplicating objects by looking at the primary keys ( relatedByAttribute ). Here's a simple JSON: [ { parentId: "<unique id>", parentName : "<name>", children : [ { childId: "<unique id>", childName: "<name>" }, { childId: "<unique id>", childName: "<name>" } ] }, { <another parent with children> } ] I've

Swift: Reflecting properties of subclass of NSManagedObject

∥☆過路亽.° 提交于 2019-12-04 08:59:11
When accessing the inner structure of a subclass of NSManagedObject using a Mirror, all managed variables are ignored. public class Foo: NSManagedObject { @NSManaged var bar: String? } var f: Foo = ... // ... creating a Foo in a valid context ... let mirror = Mirror(reflecting: f) for c in mirror.children { // children count == 0 print("\(c.label!):\(c.value)") // never executed } How can reflection mechanisms used on NSManagedObjects. The accessor methods for Core Data properties are synthesized dynamically at runtime. You can enumerate the attributes of a Core Data entity using the entity

RestKit: how to remove core data entries to keep the content in sync with the server?

那年仲夏 提交于 2019-12-04 06:51:17
I'm using the RestKit RKObjectManager to get data from my server and store in core data (see my other post ) I want to configure the deletion behavior of the old entries left in the database. I saw there's a deletionPredicate property in the RKEntityMapping class but I understand that it is used only when the service actually returns the objects to be deleted flagged as 'to-be-deleted'. (am I right?) In my case when some objects have to be deleted, they're just NOT returned by the server and I'd like to make my client app understand that this means it should remove them. Is that possible? And

Fetched Property in Core Data

孤人 提交于 2019-12-04 06:50:06
In my core data model, a Person has one or more Cars , specified by the unordered to-many relationship 'Cars'. Frequently, I need to retrieve a Person's cars ordered by datePurchased , or by dateLastUsed . Until now, I have been adding my own method to Person for carsByDatePurchased . This uses a sort descriptor to sort the NSSet cars and return an NSArray. Could/should I instead use a Fetched Property for this? I am experiencing some performance overhead using the sort descriptor every time I need the cars in a certain order, even going so far as implementing my own caching of

Objective c - Core Data saving approach

不打扰是莪最后的温柔 提交于 2019-12-04 06:44:17
问题 I have some NSManagedObject subclass in my app, and I'm trying to understand when and how to save changes. I will try to explain myself, for example class A is NSManagedObject subclass. During app life cycle I do: App launched ... Create an instance of class A ... Change some properties of A instance ... App go to background ... App becomes active again ... Change some more properties of A instance ... App terminates When do I need to call [context save:] ?? Do I call it after every change in

Failed to call Designated Initializer on NSManagedObject Class — CoreData

女生的网名这么多〃 提交于 2019-12-04 05:51:21
问题 I have really been stuck on this issue and I have referred to this stackoverflow post but my application still crashes with the issue: Failed to call Designated Initializer on NSManagedObject Class So, I have multiple entities and I have subclassed the NSManagedObject . Let's pretend I have entities named: FirstEntity, SecondEntity, ThirdEntity, Fourth Entity, FifthEntity. Let's also pretend I have two attributes named firstAttribute, secondAttribute in each Entity. I went into the xcdatamold

NSUndoManager, Core Data and selective undo/redo

做~自己de王妃 提交于 2019-12-04 05:47:53
I'm working on a core data application that has a rather large hierarchy of managed objects similar to a tree. When a base object is created, it creates a few child objects which in turn create their own child objects and so on. Each of these child objects may gather information using NSURLConnections. Now, I'd like to support undo/redo with the undoManager in the managedObjectContext. The problem is, if a user creates a base object, then tries to undo that action, the base object is not removed. Instead, one or more of the child objects may be removed. Obviously this type of action is

Xcode 9 build issue with Date vs NSDate for NSManagedObject

穿精又带淫゛_ 提交于 2019-12-04 04:57:57
Xcode 9 generates different code for Date type attribute of the entity in simulator vs device. I have codegen feature under Class set to category/extension in coredata. Until Xcode 8.3 (latest) it was all working fine ( NSDate always). Below is the auto generated code by Xcode 9 (Swift 4) for the attribute - On Device :- @NSManaged public var requiredDate: Date? AND, On Simulator :- @NSManaged public var requiredDate: NSDate? Anyone encountered this problem? What is the best solution for a project with 50+ members to fix this until an Xcode update fix it (I hope there is an apple radar for

NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault

匆匆过客 提交于 2019-12-04 03:44:59
My iOS app uses core data via multiple threads. I am getting some crash reports with the following message: "'NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault for '0x1e07a9b0 '' I understand what is causing this problem - that the object was deleted but another thread is trying to access it. I am working to solve the problem but I want to add a check in the background thread to see if the object will fault in this manner. My code at the moment relates to myObject.myValue . Is it possible to do some check, such as: if (!myObject.myValue) { return; } ... so that it

How to insert new data to entity in Swift3?

与世无争的帅哥 提交于 2019-12-04 02:43:35
In swift previously, I was able to use a code like this to add new data to my "TestEntity" in my data model. NSManagedObject was created for my "TestEntity" and I was able to set its attributes with the "dot" syntax At the end, I would save the context let entity=NSEntityDescription.insertNewObject(forEntityName: "TestEntity", into: context) as! TestEntity entity.testAttribute="test value" context.save() This code does not work in Swift3. When I run it, i get the following runtime error: Could not cast value of type 'NSManagedObject_TestEntity_' (0x175306b0) to 'testCoreData.TestEntity'