Re: CoreData in Objective-C in Xcode 11


Chris Hanson
 

On May 12, 2020, at 5:56 PM, Alex Zavatone via groups.io <zav@...> wrote:

I’m going through Chris Eidhof’s Core Data tutorial here https://www.objc.io/issues/4-core-data/full-core-data-application/ and noticed something that ends up creating a build error directly after creating creating a simple ManagedObjectModel from the Editor > Create NSManagedObject Subclass.

Two Swift files are created, not Objective-C files.

Item+CoreDataProperties.swift
Item+CoreDataClass.swift

The creation of these classes create a build errors right away.  Is it expected that an Objective C project will create Swift MOC subclasses?  Is anyone using CoreData in Xcode 11?
I’m curious what’a happening here.

The language used for creating NSManagedObject (not MOC) subclasses is set in the data model’s file inspector. It defaults to Swift.

Core Data data models also support automatic code generation, which is enabled by default, so if you don’t want classes generated automatically for certain entities you need to specify that in their inspector. You can also specify that just a class extension be generated for a particular entity, so you still own the overall class definition and just the attribute & relationship accessors will be handled for you.

  -- Chris

Join {cocoa@apple-dev.groups.io to automatically receive all group messages.