0
是否可以使用键值编码来访问对象的超类属性?如何使用键值编码访问超类属性?
我想是这样的:
class Bar: Foo {
var shouldOverridePropertyOfFoo: Bool = false
var propertyOfFoo: String {
if shouldOverrideProperty {
return "property of Bar"
} else {
return value(forKeyPath: "super.propertyOfFoo") as! String
}
}
}
但是,我得到这个运行时错误:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '
[<MyModule.Bar 0x2da2cf003e00> valueForUndefinedKey:]
: this class is not key value coding-compliant for the keysuper
.'
注:我想弄清楚how to override private method and call super in swift?