【发布时间】:2017-11-09 09:27:28
【问题描述】:
我注意到我的应用会在以下情况下崩溃:
- 为 NSWindow 使用自定义 Swift 类
- 在窗口上添加NSScrollView
- 运行特定目标(我在这个项目中还有 2 个,它们在相同条件下都可以正常工作)
调用它的代码如下:
guard let alertWindow = alert.window else {//It crashes here
//other code
return false
}
类实现为空。它只是 NSWindow 子类(如果我使用 NSWindow 一切正常)
class CustomAlertWindow: NSWindow {
}
它适用于空的 Objective-C 子类
@interface CustomAlertWindow: NSWindow
@end
@implementation CustomAlertWindow
@end
有人遇到过这样的崩溃吗?看起来它试图订阅 NSScrollView 事件。并且不知何故失败了。可能我的目标有问题,或者可能只是 Cocoa/XCode/等。错误...
目前我无法在空项目中重现它,但我会继续尝试。
当我重载addObserver方法时,我发现keyPath是“contentLayoutRect”
override func addObserver(_ observer: NSObject, forKeyPath keyPath: String, options: NSKeyValueObservingOptions = [], context: UnsafeMutableRawPointer?) {
super.addObserver(observer, forKeyPath: keyPath, options: options, context: context)
}
两者相同:
- 斯威夫特 3
- XCode 版本 8.3.3 (8E3004b)
- macOS:10.12.5 (16F73)
和
- 斯威夫特 3.2
- Xcode 版本 9.0 (9A235)
- macOS:10.13 (17A365)
附: 无论如何,感谢您的关注。
【问题讨论】: