我有以下一段代码
protocol JsonParseDescriptor {
//some required methods
func parsePrimitives() {
}
extension JsonParseDescriptor where Self: NSManagedObject {
func parsePrimitives() {
self.setValue(1, forKey: "id") //this throws an error in swift stating Ambiguous use of setValueForKey
self.setValue(1, forKey: "id") //this does not throw any compile-time error
}
}
任何想法为什么 setValue:ForKey: 会导致此错误?有趣的是, setValue:ForKeyPath: 不会导致这个问题。我只是害怕使用后者,因为它会导致任何副作用,并且除了 setValue:ForKey: 有什么想法吗?