无法将“enum”类型的值转换为Swift.CVarArg'

时间:2018-01-12 01:37:22

标签: swift core-data enums

我有一个如下所示的枚举:

enum Period: String {

    case first    = "1st"
    case second   = "2nd"
    case third    = "3rd"
    case overtime = "Overtime"
}

我将值存储在CoreData中,但是,当我尝试执行以下谓词时,我收到以下错误。

let predicatePeriod = NSPredicate(format: "%K = %@", #keyPath(Shifts.period), period as! CVarArg)

Could not cast value of type 'Time_on_Ice.Period' (0x1052fad10) to 'Swift.CVarArg' (0x10a1a3b88).

在我将as! CVarArg作为Int之前,编译器强迫我添加enum前一段extension Shifts { @nonobjc public class func fetchRequest() -> NSFetchRequest<Shifts> { return NSFetchRequest<Shifts>(entityName: "Shifts") } @NSManaged public var date: NSDate? @NSManaged public var period: String? @NSManaged public var timeOnIce: Int16 @NSManaged public var gameRelationship: Games? @NSManaged public var playersRelationship: Players? }

更新

{{1}}

0 个答案:

没有答案