class ArrayTransform : ValueTransformer {
override func transformedValue(_ value: Any?) -> Any? {
return NSKeyedArchiver.archivedData(withRootObject:value)
}
override func reverseTransformedValue(_ value: Any?) -> Any? {
return NSKeyedUnarchiver.unarchiveObject(with: value as! Data)
}
}
在上面的代码中,我无法覆盖。那么如何在Swift 3.0中实现它?
open class func allowsReverseTransformation() -> Bool
open class func transformedValueClass() -> Swift.AnyClass
答案 0 :(得分:2)
自动完成不一定有效。覆盖执行工作。只需复制它们,就像这样:
class ArrayTransform : ValueTransformer {
override class func transformedValueClass() -> Swift.AnyClass {
return NSData.self // or whatever
}
override class func allowsReverseTransformation() -> Bool {
return true // or whatever
}
// ... your other overrides go here ...
}