Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
194 views
in Technique[技术] by (71.8m points)

ios - Xcode-beta 8. Can't create core data

I have been trying to add core data. And every time I got the same error:

error: filename "EntityName +CoreDataClass.swift" used twice: '/Users/userName/Desktop/Development/MyApp/AppName/EntityName +CoreDataClass.swift' and '/Users/userName/Library/Developer/Xcode/DerivedData/AppName-dgwzrmxsetzvtedibxrazuutjwnh/Build/Intermediates/AppName.build/Debug-iphoneos/AppName.build/DerivedSources/CoreDataGenerated/Model/EntityName +CoreDataClass.swift'

I add core data using the following steps:
1.New file/ DataModel; save it in the root dir of my project
select Model.xcdatamodeld and add entity, add several attributes, save, editor/create NSManagedObjectClass Subclass.

As a result I observe 4 new files in navigator: Model.xcdatamodeld, EntityName+CoreDataProperties.swift, EntityName +CoreDataClass.swift, _COREDATA_DATAMODELNAME_+CoreDataModel.swift

their content: _COREDATA_DATAMODELNAME_+CoreDataModel.swift:

import Foundation
import CoreData

___COREDATA_DATAMODEL_MANAGEDOBJECTCLASSES_IMPLEMENTATIONS___

EntityName +CoreDataClass.swift:

import Foundation
import CoreData


class EntityName: NSManagedObject {

}

EntityName+CoreDataProperties.swift:

import Foundation
import CoreData

extension EntityName {

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

    @NSManaged var str: String?

}

What I have tried:
1. Clean build, remove DerivedData, delete content of var/folders, restart
2. Delete generated files, displayed in navigator

All my efforts were out of luck.
What I am doing wrong?

question from:https://stackoverflow.com/questions/38409074/xcode-beta-8-cant-create-core-data

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There are two bugs in XCode 8 here:

1 - If you change the Codegen dropdown, it's new value isn't saved in Model.xcdatamodel. You have to change something else to get it to save. For example change the class name; build; change the class name back; build again.

2 - The generated code is placed in DerivedData in the Intermediates folder, but it only happens if the folder doesn't already exist. The workaround is to do a clean then a build.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...