Swift 3: 'Int' 类型的表达式模式无法匹配 'UnsafeMutableRawPointer' 类型的值
Swift 3: expression pattern of type 'Int' cannot match values of type 'UnsafeMutableRawPointer'
我正在将一个应用程序迁移到 Swift 3,但 Xcode 使用此函数时出现错误:
错误是在案例条件下("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
是为了确保上下文不为nil
&
获取指向 MyObservationContext
的指针,因此它可以将指针与指针进行比较。
我正在将一个应用程序迁移到 Swift 3,但 Xcode 使用此函数时出现错误:
错误是在案例条件下("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
是为了确保上下文不为nil
&
获取指向 MyObservationContext
的指针,因此它可以将指针与指针进行比较。