我有一个用纯Swift编写的Space类。而且我需要在AppKit环境中使用它。我尝试构建控制器以从空间获取/设置数据到接口并返回。首先,我制作了SpaceController,在其中我将var _space
定义为Space<SomeClass, Double>
(确定)和变量axes
,该变量接受并设置_space.axes
@objc var axes:[Any] {
defer { Swift.print ("will return \(_space?.axes ?? [])") }
return _space?.axes ?? []
}
@objc func setAxes(_ axes:[Any]) {
if let axes = axes as? [Axis<Double>] {
_space?.axes = axes
}
}
当我尝试观察更改时出现问题。
如果我将willChange..
或didChange...
放在任何地方(在这种情况下,设置_space
)
var _space: Space<SomeClass, Double>? = nil {
willSet {
willChangeValue(for: \SpaceController.axes)
}
didSet {
didChangeValue(for: \SpaceController.axes)
}
}
我遇到错误:
NSForwarding: warning: object 0x60c000067ac0 of class '_TtGC5Space4AxisSd_' does not implement methodSignatureForSelector: -- trouble ahead
Unrecognized selector -[_TtGC5Space4AxisSd_ addObserver:forKeyPath:options:context:]
2018-07-31 17:37:37.780765+0200 SpaceView[33012:2077391] Unrecognized selector -[_TtGC5Space4AxisSd_ addObserver:forKeyPath:options:context:]
如何观察Space.axes数组的变化?