我有一个如下所示的枚举:
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}}