Xcode-beta 8. Can't create core data

前端 未结 9 1282
伪装坚强ぢ
伪装坚强ぢ 2020-12-13 09:06

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/         


        
相关标签:
9条回答
  • 2020-12-13 09:44

    Follow these steps,

    1. Disable automatic generation for each entity individually by setting the "Codegen" setting to "Manual/None" for the entity.

    2. Change entity name to something else to get it to save. For example change the class name; build; change the class name back; build again.

    0 讨论(0)
  • 2020-12-13 09:48

    Tom Harrington Answer is correct. However, there is a way to add your own functions and/or vars without doing any of the two mentioned options.

    Just create an extension to the class. (make sure you name the swift file something different than the standard auto-generated NSManagesObject files.)

    For example. If you have an entity called MyEntity you could add a swift file called MyEntityExtension.swift which could look something like this:

    import Foundation
    import CoreData
    import UIKit
    
    
    extension MyEntity {
    
        var color: UIColor {
            get {
                return self.colorValue as! UIColor
            }
            set {
                if newValue.isMember(of: UIColor.self) {
                    self.colorValue = newValue
                }
            }
        }
    
    }
    
    0 讨论(0)
  • 2020-12-13 09:49

    For everyone having trouble getting autogen to work:

    I had to set the "com.apple.syncservices.Syncable" to "NO" on the User Info settings for the Entity.

    Maybe that helps out.

    0 讨论(0)
提交回复
热议问题