I get the following error after adding a string property called Unique Identifier
to my Enitiy
/NSManagedObject
called Labels
. However it is not the Unique Identifier
which the complier is unhappy with.
2016-08-20 02:20:08.394 AN[22499:8730414] -[AN.Labels folders]: unrecognized selector sent to instance 0x7ffe907e1a80 2016-08-20 02:20:08.405 AN[22499:8730414] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AN.Labels folders]: unrecognized selector sent to instance 0x7ffe907e1a80'
Here's my NSManagedObject class
class Labels: NSManagedObject {
@NSManaged var title: String?
@NSManaged var details: String
@NSManaged var date: NSDate?
@NSManaged var uniqueIdentifier: NSString?
@NSManaged var arrayOfFolders: [Folders]
@NSManaged var folder: Folders?
@NSManaged var folders: NSSet
override func awakeFromFetch() {
super.awakeFromFetch()
self.regenerateFolders()
}
func regenerateFolders() {
let date = NSSortDescriptor(key: "date", ascending: false)
if let array = folders.sortedArrayUsingDescriptors([date]) as? [Folders] {
self.arrayOfFolders = array
}
}
}
I have made sure the app uses the new coreData
model and have the following in my CoreData
Stack. I haven't had this issue for some time as my app automatically updates to use the latest core data model.
var storeDirectoryURL: NSURL {
return try! NSFileManager.defaultManager().URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true)
}
var storeURL: NSURL {
return self.storeDirectoryURL.URLByAppendingPathComponent("SingleViewCoreData.sqlite")
}
func setupCoreData() {
let modelURL = NSBundle.mainBundle().URLForResource("AN", withExtension: "momd")
let model = NSManagedObjectModel(contentsOfURL: modelURL!)
try! NSFileManager.defaultManager().createDirectoryAtURL(self.storeDirectoryURL, withIntermediateDirectories: true, attributes: nil)
let coordinator = NSPersistentStoreCoordinator(managedObjectModel: model!)
let options = [NSMigratePersistentStoresAutomaticallyOption: true, NSInferMappingModelAutomaticallyOption: true]
try! coordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: self.storeURL, options: options)
managedObjectContext = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType)
managedObjectContext.persistentStoreCoordinator = coordinator
managedObjectContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
}
Does anybody have any suggestions ?
Check the relationship between Labels and Folders in the core data model. You may have the inverse relationship named something other than Labels.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With