我正在将应用程序迁移到 Swift 3,但是Xcode在这个函数中抛出一个错误: 错误是在案例条件(“contentSize”,MyObservationContext) 我这样做是为了更新uiwebview的内容大小 var MyObservationContext = 0ov
错误是在案例条件(“contentSize”,MyObservationContext)
我这样做是为了更新uiwebview的内容大小
var MyObservationContext = 0 override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { guard let keyPath = keyPath else { super.observeValue(forKeyPath: nil, of: object, change: change, context: context) return } switch (keyPath, context) { case("contentSize", MyObservationContext): webviewHeightConstraint.constant = TextoHtml.scrollView.contentSize.height default: super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context) } }
我愿意接受建议,谢谢.
案件需要case("contentSize", .some(&MyObservationContext)):
.some是为了确保上下文不是零
&安培;获取指向MyObservationContext的指针,以便它可以将指针与指针进行比较.