Search code examples
iosswiftuiwebviewswift3

Swift 3: expression pattern of type 'Int' cannot match values of type 'UnsafeMutableRawPointer'


I'm migrating an app to Swift 3 but Xcode is throwing an error with this function:

The error is at the case condition ("contentSize", MyObservationContext) i'm doing this for update the content size of a 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)
    }
}

I'm open for suggestions, thanks.


Solution

  • The case needs to be

    case("contentSize", .some(&MyObservationContext)):
    

    .some is to make sure the context is not nil

    & gets the pointer to MyObservationContext so it can compare a pointer to a pointer.