Reputation: 3589
I've been trying to figure this one out for days :(
given:
println("\(context)")
if context == nil {
println("context is nil")
}
let boardEntity: NSManagedObject = NSEntityDescription.insertNewObjectForEntityForName("Board", inManagedObjectContext: context) as NSManagedObject
let cardQueueEntity: NSManagedObject = NSEntityDescription.insertNewObjectForEntityForName("CardQueue", inManagedObjectContext: context) as NSManagedObject
boardEntity saves fine. I've even verified this in the sql file directly.
cardQueueEntity produces the following error:
+entityForName: could not locate an entity named 'CardQueue' in this model.
<NSManagedObjectContext: 0x6080001dfd10>
cardQueueEntity
declarationprintln("\(context.persistentStoreCoordinator.managedObjectModel.entitiesByName)")
shows all entities.here's the core data stack i'm using (based on http://www.cimgf.com/2014/06/08/the-core-data-stack-in-swift),
@lazy var context: NSManagedObjectContext = {
let modelURL = NSBundle.mainBundle().URLForResource("Tello", withExtension: "momd")
let mom = NSManagedObjectModel(contentsOfURL: modelURL)
let psc = NSPersistentStoreCoordinator(managedObjectModel: mom)
let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
let storeURL = (urls[urls.endIndex-1]).URLByAppendingPathComponent("Tello.sqlite")
var error: NSError? = nil
var store = psc.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: storeURL, options: nil, error: &error)
if (store == nil) {
println("Failed to load store")
}
var managedObjectContext = NSManagedObjectContext()
managedObjectContext.persistentStoreCoordinator = psc
return managedObjectContext
}()
but I get the same issue with the default Apple stack as well.
Thanks!!
Upvotes: 2
Views: 438
Reputation: 3589
This may or may not help you if you're having the same issue, but what resolved it for me was upgrading my mac to the Yosemite beta and from XCode beta1 to beta3.
I can't say which of those two things did it - XCode makes the most sense, so try that first.
(On Mavericks editing the deployment target to explicitly build for 10.9 didn't fix the problem for me.)
Upvotes: 0