Xcode-beta 8. Can't create core data

前端 未结 9 1317
伪装坚强ぢ
伪装坚强ぢ 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条回答
  •  -上瘾入骨i
    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
                }
            }
        }
    
    }
    

提交回复
热议问题