Reputation: 2066
I've had many many issues with Xcode in general, but this just started happening to all my projects.
I've created a new entity, my core data model has the correct 'Target Membership' selected.
But once I try selecting 'Create NSManagedObject Subclass' of my new entity, the wizard properly takes me through all the necessary steps and I get the following generated Swift code:
import Foundation
import CoreData
class CoreDatGeneric: NSManagedObject {
// Insert code here to add functionality to your managed object subclass
}
import Foundation
import CoreData
class CoreDatGeneric: NSManagedObject {
// Insert code here to add functionality to your managed object subclass
}
However... I can't use this new Swift class named CoreDatGeneric
ANYWHERE in my code...
For example,
let data = DoreDatGeneric()
results in a compiler error stating Use of unresolved identifier 'CoreDatGeneric'
I have no idea why this is happening all of a sudden, all my other older Core Data entities work just fine, but I'm stuck at a point of not being able to use core data anymore on any of my projects.
I'm very worried about upgrading to Xcode 8, because of the negative reviews the latest Xcode had received. I'm using Xcode 7 right now.
Upvotes: 1
Views: 560
Reputation: 2221
Go to data model inspector panel and select Codegen to 'Manual/None'. Create Managed Subclass under Editor. Xcode will create two swift files. One is *Properties.swift, an extension file where all properties from your model are included (Xcode will overwrite this file overtime you create subclass). The other one is *Class.swift where you can add custom class behaviors. Without writing any code you should be able to call
let data = CoreDatGeneric()
in your ViewController.
If the Codegen say 'Class Definition' then you don't have to do Create Managed Subclass because the class will be created for you when you build project (the files won't show up in Project Inspector). However you can still create a variable as written above in a viewController (for example).
Upvotes: 1