【发布时间】:2016-07-03 20:22:52
【问题描述】:
我正在尝试通过子类化将存储属性添加到 NSBezierPath。然而,以下代码使 Playground 崩溃:
import Cocoa
class MyNSBezierPath: NSBezierPath {
private var someProperty: Bool
override init() {
someProperty = false
super.init()
}
required init?(coder aDecoder: NSCoder) {
self.someProperty = false
super.init(coder: aDecoder)
}
}
// the following line causes the Playground to fully crash
let somePath = MyNSBezierPath()
Playground 错误(如下)似乎表明 NSCoder 存在问题,但我认为像这样将调用传递给超类就可以了。我做错了什么?
UNCAUGHT EXCEPTION (NSInvalidUnarchiveOperationException):
*** - [NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class
(__lldb_expr_22.MyNSBezierPath) for key (root);
the class may be defined in source code or a library that is not linked
UserInfo: { "__NSCoderInternalErrorCode" = 4864;}
Hints: None
【问题讨论】:
-
嗯...阅读this other answer 听起来子类化 NSBezierPath 可能是一个坏的想法。也许我将不得不使用包装器 - 这很遗憾,因为它使代码不那么清晰:(
-
这也是一个令人讨厌的崩溃...我有点惊讶 Xcode 不能更好地处理它。
-
你和我都...
标签: swift macos subclassing nsbezierpath