CoreData in Objective-C in Xcode 11


Alex Zavatone
 

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.

Thanks.


<unknown>:0: error: filename "Item+CoreDataClass.swift" used twice: '/Users/zav/Developer/BasicCoreData/BasicCoreData/Item+CoreDataClass.swift' and '/Users/zav/Library/Developer/Xcode/DerivedData/BasicCoreData-ddewwduzsmelbzawnlblirktothl/Build/Intermediates.noindex/BasicCoreData.build/Debug-iphonesimulator/BasicCoreData.build/DerivedSources/CoreDataGenerated/ItemModel/Item+CoreDataClass.swift'
<unknown>:0: note: filenames are used to distinguish private declarations with the same name
<unknown>:0: error: filename "Item+CoreDataProperties.swift" used twice: '/Users/zav/Developer/BasicCoreData/BasicCoreData/Item+CoreDataProperties.swift' and '/Users/zav/Library/Developer/Xcode/DerivedData/BasicCoreData-ddewwduzsmelbzawnlblirktothl/Build/Intermediates.noindex/BasicCoreData.build/Debug-iphonesimulator/BasicCoreData.build/DerivedSources/CoreDataGenerated/ItemModel/Item+CoreDataProperties.swift'
<unknown>:0: note: filenames are used to distinguish private declarations with the same name


error: Multiple commands produce '/Users/zav/Library/Developer/Xcode/DerivedData/BasicCoreData-ddewwduzsmelbzawnlblirktothl/Build/Intermediates.noindex/BasicCoreData.build/Debug-iphonesimulator/BasicCoreData.build/Objects-normal/x86_64/Item+CoreDataClass.o':
1) Target 'BasicCoreData' (project 'BasicCoreData') has compile command for Swift source files
2) Target 'BasicCoreData' (project 'BasicCoreData') has compile command for Swift source files

error: Multiple commands produce '/Users/zav/Library/Developer/Xcode/DerivedData/BasicCoreData-ddewwduzsmelbzawnlblirktothl/Build/Intermediates.noindex/BasicCoreData.build/Debug-iphonesimulator/BasicCoreData.build/Objects-normal/x86_64/Item+CoreDataProperties.o':
1) Target 'BasicCoreData' (project 'BasicCoreData') has compile command for Swift source files
2) Target 'BasicCoreData' (project 'BasicCoreData') has compile command for Swift source files


–––––––––––––––––––––

Item+CoreDataClass.swift


import Foundation
import CoreData

@objc(Item)
public class Item: NSManagedObject {

}


–––––––––––––––––––––

Item+CoreDataProperties.swift


import Foundation
import CoreData


extension Item {

    @nonobjc public class func fetchRequest() -> NSFetchRequest<Item> {
        return NSFetchRequest<Item>(entityName: "Item")
    }

    @NSManaged public var order: Int64
    @NSManaged public var title: String?
    @NSManaged public var parent: Item?
    @NSManaged public var child: Item?

}





Steve Christensen <punster@...>
 

Check the entity inspector in the model file. As I recall, there are options for auto-creating Obj-C it Swift class files, or manual if you want to create and edit the class files yourself. Perhaps it’s now defaulting to Swift. (I’m not around my computer now, so it’s a guess.)

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.

Thanks.


<unknown>:0: error: filename "Item+CoreDataClass.swift" used twice: '/Users/zav/Developer/BasicCoreData/BasicCoreData/Item+CoreDataClass.swift' and '/Users/zav/Library/Developer/Xcode/DerivedData/BasicCoreData-ddewwduzsmelbzawnlblirktothl/Build/Intermediates.noindex/BasicCoreData.build/Debug-iphonesimulator/BasicCoreData.build/DerivedSources/CoreDataGenerated/ItemModel/Item+CoreDataClass.swift'
<unknown>:0: note: filenames are used to distinguish private declarations with the same name
<unknown>:0: error: filename "Item+CoreDataProperties.swift" used twice: '/Users/zav/Developer/BasicCoreData/BasicCoreData/Item+CoreDataProperties.swift' and '/Users/zav/Library/Developer/Xcode/DerivedData/BasicCoreData-ddewwduzsmelbzawnlblirktothl/Build/Intermediates.noindex/BasicCoreData.build/Debug-iphonesimulator/BasicCoreData.build/DerivedSources/CoreDataGenerated/ItemModel/Item+CoreDataProperties.swift'
<unknown>:0: note: filenames are used to distinguish private declarations with the same name


error: Multiple commands produce '/Users/zav/Library/Developer/Xcode/DerivedData/BasicCoreData-ddewwduzsmelbzawnlblirktothl/Build/Intermediates.noindex/BasicCoreData.build/Debug-iphonesimulator/BasicCoreData.build/Objects-normal/x86_64/Item+CoreDataClass.o':
1) Target 'BasicCoreData' (project 'BasicCoreData') has compile command for Swift source files
2) Target 'BasicCoreData' (project 'BasicCoreData') has compile command for Swift source files

error: Multiple commands produce '/Users/zav/Library/Developer/Xcode/DerivedData/BasicCoreData-ddewwduzsmelbzawnlblirktothl/Build/Intermediates.noindex/BasicCoreData.build/Debug-iphonesimulator/BasicCoreData.build/Objects-normal/x86_64/Item+CoreDataProperties.o':
1) Target 'BasicCoreData' (project 'BasicCoreData') has compile command for Swift source files
2) Target 'BasicCoreData' (project 'BasicCoreData') has compile command for Swift source files


–––––––––––––––––––––

Item+CoreDataClass.swift


import Foundation
import CoreData

@objc(Item)
public class Item: NSManagedObject {

}


–––––––––––––––––––––

Item+CoreDataProperties.swift


import Foundation
import CoreData


extension Item {

    @nonobjc public class func fetchRequest() -> NSFetchRequest<Item> {
        return NSFetchRequest<Item>(entityName: "Item")
    }

    @NSManaged public var order: Int64
    @NSManaged public var title: String?
    @NSManaged public var parent: Item?
    @NSManaged public var child: Item?

}





Alex Zavatone
 

It works as expected in Xcode 10.  : /

On May 12, 2020, at 11:54 PM, Steve Christensen via groups.io <punster@...> wrote:

Check the entity inspector in the model file. As I recall, there are options for auto-creating Obj-C it Swift class files, or manual if you want to create and edit the class files yourself. Perhaps it’s now defaulting to Swift. (I’m not around my computer now, so it’s a guess.)

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.

Thanks.


<unknown>:0: error: filename "Item+CoreDataClass.swift" used twice: '/Users/zav/Developer/BasicCoreData/BasicCoreData/Item+CoreDataClass.swift' and '/Users/zav/Library/Developer/Xcode/DerivedData/BasicCoreData-ddewwduzsmelbzawnlblirktothl/Build/Intermediates.noindex/BasicCoreData.build/Debug-iphonesimulator/BasicCoreData.build/DerivedSources/CoreDataGenerated/ItemModel/Item+CoreDataClass.swift'
<unknown>:0: note: filenames are used to distinguish private declarations with the same name
<unknown>:0: error: filename "Item+CoreDataProperties.swift" used twice: '/Users/zav/Developer/BasicCoreData/BasicCoreData/Item+CoreDataProperties.swift' and '/Users/zav/Library/Developer/Xcode/DerivedData/BasicCoreData-ddewwduzsmelbzawnlblirktothl/Build/Intermediates.noindex/BasicCoreData.build/Debug-iphonesimulator/BasicCoreData.build/DerivedSources/CoreDataGenerated/ItemModel/Item+CoreDataProperties.swift'
<unknown>:0: note: filenames are used to distinguish private declarations with the same name


error: Multiple commands produce '/Users/zav/Library/Developer/Xcode/DerivedData/BasicCoreData-ddewwduzsmelbzawnlblirktothl/Build/Intermediates.noindex/BasicCoreData.build/Debug-iphonesimulator/BasicCoreData.build/Objects-normal/x86_64/Item+CoreDataClass.o':
1) Target 'BasicCoreData' (project 'BasicCoreData') has compile command for Swift source files
2) Target 'BasicCoreData' (project 'BasicCoreData') has compile command for Swift source files

error: Multiple commands produce '/Users/zav/Library/Developer/Xcode/DerivedData/BasicCoreData-ddewwduzsmelbzawnlblirktothl/Build/Intermediates.noindex/BasicCoreData.build/Debug-iphonesimulator/BasicCoreData.build/Objects-normal/x86_64/Item+CoreDataProperties.o':
1) Target 'BasicCoreData' (project 'BasicCoreData') has compile command for Swift source files
2) Target 'BasicCoreData' (project 'BasicCoreData') has compile command for Swift source files


–––––––––––––––––––––

Item+CoreDataClass.swift


import Foundation
import CoreData

@objc(Item)
public class Item: NSManagedObject {

}


–––––––––––––––––––––

Item+CoreDataProperties.swift


import Foundation
import CoreData


extension Item {

    @nonobjc public class func fetchRequest() -> NSFetchRequest<Item> {
        return NSFetchRequest<Item>(entityName: "Item")
    }

    @NSManaged public var order: Int64
    @NSManaged public var title: String?
    @NSManaged public var parent: Item?
    @NSManaged public var child: Item?

}






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