我想通過繼承將存儲的屬性添加到NSBezierPath中。但是下面的代碼崩潰遊樂場:爲什麼NSBezierPath這個簡單的子類會使我的OSX 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()
操場錯誤(下)似乎表明與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
嗯...閱讀[這個其他答案](http://stackoverflow.com/questions/29867782/uibezierpath-subclass-initializer)這聽起來像繼承NSBezierPa這可能是一個**糟糕的主意。也許我必須去一個包裝 - 這是一個恥辱,因爲它使得代碼更清晰:( –
這也是一個令人討厭的崩潰...我有點驚訝Xcode不處理它更好 –
你和我都... –