Posts

Post not yet marked as solved
6 Replies
8.6k Views
Dear everyone,I am relatively new to Core Data and I was trying to create a small app in Swift UI to display a list of elements and being able to add new ones.I created an entity (Codegen: Manual/None) with the following fields:- city: String- country: String- createdAt: Date- date: Date- id: UUID- summary: StringAn I created the equivalent class:public class EventItems: NSManagedObject, Identifiable { @NSManaged public var id: UUID @NSManaged public var city: String @NSManaged public var country: String @NSManaged public var date: Date @NSManaged public var createdAt: Date @NSManaged public var summary: String }And the following extensionextension EventItems { static func getAllItems() -> NSFetchRequest<EventItems> { let request: NSFetchRequest<EventItems> = NSFetchRequest<EventItems>(entityName: "EventItems") request.sortDescriptors = [NSSortDescriptor(key: "date", ascending: true)] return request } }In a SwiftUI view, I set the Environement and then have a button to save a new element:@Environment(\.managedObjectContext) var managedObjectContextButton(action: { let eventItem:EventItems = EventItems(context: self.managedObjectContext) eventItem.id = UUID() eventItem.city = self.city eventItem.country = self.country eventItem.date = self.date eventItem.createdAt = Date() eventItem.summary = self.summary do { try self.managedObjectContext.save() } catch { print(error) } }) { Text("Save") }In my View to add a new element to the entity, when I press the save button, the application crashes with the following error:2019-10-20 20:50:04.209071+0200 EventLogger[14093:945375] [error] error: No NSEntityDescriptions in any model claim the NSManagedObject subclass 'EventLogger.EventItems' so +entity is confused. Have you loaded your NSManagedObjectModel yet ?CoreData: error: No NSEntityDescriptions in any model claim the NSManagedObject subclass 'EventLogger.EventItems' so +entity is confused. Have you loaded your NSManagedObjectModel yet ?2019-10-20 20:50:04.209361+0200 EventLogger[14093:945375] [error] error: +[EventLogger.EventItems entity] Failed to find a unique match for an NSEntityDescription to a managed object subclassCoreData: error: +[EventLogger.EventItems entity] Failed to find a unique match for an NSEntityDescription to a managed object subclass2019-10-20 20:50:04.219017+0200 EventLogger[14093:945375] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'An NSManagedObject of class 'EventLogger.EventItems' must have a valid NSEntityDescription.'Thanks for your help 🙂
Posted Last updated
.
Post marked as solved
2 Replies
1.4k Views
Hi guys,I am trying to access the address book contacts using contactStore.unifiedMeContactWithKeys(toFetch: keys), but it is returning me the following error:2019-05-30 10:09:47.835832+0200 macOSContactManager[3549:185878] Could not get real path for Address Book lock folder: open() for F_GETPATH failed.2019-05-30 10:09:47.836157+0200 macOSContactManager[3549:185878] Unable to open file lock: <ABProcessSharedLock: 0x600001778140: name=(null), lockFilePath=(null), localLock=<NSRecursiveLock: 0x600002902d10>{recursion count = 0, name = nil}, fileDescriptor=-1> Error Domain=NSPOSIXErrorDomain Code=14 "Bad address" UserInfo={ABFileDescriptor=-1}And then this is the error from thrownError Domain=CNErrorDomain Code=200 "Updated Record Does Not Exist" UserInfo={NSLocalizedDescription=Updated Record Does Not Exist, NSLocalizedFailureReason=The save request failed because it updates a record that does not exist or has already been deleted.}Thanks for your help
Posted Last updated
.