I updated my iOS app project recently to iOS 10. Now I\'m trying to change the Core Data Model of my app but the new NSManagedObject subclasses which Xcode generates are bro
After I renamed the following:
From: YourEntity+CoreDataClass.swift To: YourEntity.swift
and
From: YourEntity+CoreDataProperties.swift To: YourEntityCoreDataProperties.swift
then it works. It looks like "+" is causing the problem.
I have a Flights Entity and these settings in the Data Model Inspector worked for me :
Set the Name to nothing(You will see some grayed out text of "NSManagedObject"). The default will be written as "Flights" just remove that.
Nothing in the module."Global Namespace" greyed out is what you will see.
Codegen to Manual/None.
Then Goto Editor -> Create NSManagedObject Subclass to create the swift files
Rename the Flights+CoreDataClass.swift to just Flights.swift
Here's the link to the Screenshot(For some reason imgur was rejecting it :( ) https://drive.google.com/file/d/0B8a3rG93GTRedkhvbWc5Ujl4Unc/view?usp=sharing
I finally got mine to work. Here is what I did. (Flights is one of my entities)
I setup the xcdatamodeld as follows
And then the entity as
Then I used Editor -> Create NSManagedObject Subclass
This creates two files for my flights entity
Flights+CoreDataProperties.swift
Flights+CoreDataClass.swift
I renamed Flights+CoreDataClass.swift to Flights.swift
Flights.swift is just
import Foundation
import CoreData
@objc(Flights)
public class Flights: NSManagedObject {
}
Flights+CoreDataProperties.swift is
import Foundation
import CoreData
extension Flights {
@nonobjc public class func fetchRequest() -> NSFetchRequest<Flights> {
return NSFetchRequest<Flights>(entityName: "Flights");
}
@NSManaged public var ...
}
This appears to work for me.I could not get Codegen to work in any other way, even though I tried many of the suggestions that were out there.
Also this had me scratching my head for a while and I add it as an assist. Don't forget with the new Generics version of the FetchRequest you can do this
let fetchRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName: "Flights")
On Xcode 8.2.1, I made it the way: (thanks for Daniel Chepenko)
But Xcode 8.2.1 will add a stupid . into the generated files:
Just delete the . and it will run right.
In Data Model Inspector select Current Product Module under 'Module' and Manual/None under 'Codegen'. (This allows you to edit subclass files and to regenerate CoreDataProperties.swift when you modify your attributes under the same entity.)
You can then choose Create NSManagedObjectSubclass under Editor menu. Xcode will create 2 files for you YourEntity+CoreDataClass.swift and YourEntity+CoreDataProperties.swift. Notice if you don't have the latest Xcode (8.2.1), any optional/nonoptional properties that you set in your Model Inspector will not show up correctly. You can edit in YourEntity +CoreDataProperties.swift file.
I just had a problem where I just added a Person entity in my model to the Core Data template. Then generated the NSManagedObject subclass for for that and it won't compile, giving me a Linker Error. Turns out I am supposed to change the Codegen option to Manual/None to make it work (see bottom-right part of the picture).