nsmanagedobject

Swift dynamicCast error while inserting new object to database

孤者浪人 提交于 2019-12-06 09:21:54
I have a dictionary which I have all data that I want to insert into database as new object. The problem is when I try to cast the newly created object it gives me exception in: libswift_stdlib_core.dylib`swift_dynamicCast: part of assembly code. The code that i am using is like this: var group:Group if (array.count == 0) { group = NSEntityDescription.insertNewObjectForEntityForName("Group", inManagedObjectContext:appDelegate.managedObjectContext) as Group } and the structure of Group class is like this: @objc(Group) class Group:NSManagedObject{ @NSManaged var createDate:NSString @NSManaged

managedObjectModel is nil (Cannot create an NSPersistentStoreCoordinator with a nil model)

爷,独闯天下 提交于 2019-12-06 06:46:36
I have this special case scenario, where in my app works perfectly fine for some time and crashes inconsistently after some time. The error that i get during the crash is "Cannot create an NSPersistentStoreCoordinator with a nil model" . I tried debugging my app and found that the managedObjectModel is returning NULL sometimes. To add fuel to the fire, this scenario is not at all consistent. For some time the managedObjectModel is fine. But, suddenly it returns NULL ... Here is the code that I am using to create a managed object model. - (NSManagedObjectModel *)managedObjectModel { if

How to make Deep Copy of NSManagedObject in Core Data

让人想犯罪 __ 提交于 2019-12-06 03:16:00
问题 I am trying to make a duplicate of an existing NSManagedObject and related sub-objects in Core Data. I can't seem to find an easy way to do this. I have an NSArrayController that is populated from a Core Data database. I want to take the object at the selectionIndex and make a deep copy, keeping it related to the same parent object and copying all child objects. Any assistance is appreciated! Thanks to TechZen for the link. I used the sample code from that site and used this calling code:

How to check if a relationship has been established - Core Data

ⅰ亾dé卋堺 提交于 2019-12-06 03:15:35
How would you check if a relationship has been established when adding data to core data? Currently I have a TO MANY relationship between two of my entities. I am attempting to create a detail view but am struggling and i'm not sure if its due to a relationship not being established or if my issue is with passing the data over to the new view controller. I am adding the the data to the core data entities using the following code. Does this look right when establishing a relationship between the two? ExcerciseInfo *info = [_fetchedResultsController objectAtIndexPath:indexPath]; NSManagedObject

Swift: Reflecting properties of subclass of NSManagedObject

夙愿已清 提交于 2019-12-06 02:44:54
问题 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. 回答1: The accessor methods for Core Data properties are

Fetched Property in Core Data

你。 提交于 2019-12-06 02:34:04
问题 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

Xcode 9 build issue with Date vs NSDate for NSManagedObject

时光毁灭记忆、已成空白 提交于 2019-12-06 00:05: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

Core Data NSManagedObject - tracking if attribute was changed

不打扰是莪最后的温柔 提交于 2019-12-05 23:19:52
I have an object - Config . I want to know if the Account attribute on Config has changed. When this happens, I want to send a NSNotification so that all code that cares about when the Account changes will know. My initial thought was in my NSManagedObject subclass that I would override the setAccount method to set a transient attribute AccountDidChange to true . Then in didSave if AccountDidChange was true I would send the notification and then set it back to false . Is there a better way? My issue though is that from what I've read, by changing AccountDidChange back to false , I would have

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

无人久伴 提交于 2019-12-05 22:02:22
问题 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

cast NSManagedObject to class -> Swift dynamic cast failed

天涯浪子 提交于 2019-12-05 21:33:04
i hope you can help! I have a class called Exercise: import Foundation import CoreData class Exercise: NSManagedObject { @NSManaged var name: String } and created an Entity called Exercise with an attribute "name" of type String. Now i want to access it from a ViewController: var context = (UIApplication.sharedApplication().delegate as AppDelegate).managedObjectContext! var exercise: NSManagedObject = NSEntityDescription.insertNewObjectForEntityForName("Exercise", inManagedObjectContext: context) as Exercise But if i now try and run it, the codes stops in Thread1 at swift