gpt4 book ai didi

ios - swift 3 : expression pattern of type 'Int' cannot match values of type 'UnsafeMutableRawPointer'

转载 作者:搜寻专家 更新时间:2023-10-31 22:01:56 24 4
gpt4 key购买 nike

我正在将一个应用程序迁移到 Swift 3,但 Xcode 对此函数抛出错误:

错误是在 case condition ("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 的指针,因此它可以将指针与指针进行比较。

关于ios - swift 3 : expression pattern of type 'Int' cannot match values of type 'UnsafeMutableRawPointer' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40492267/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com