Strider Strider - 7 months ago 98
iOS Question

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)
switch (keyPath, context) {
case("contentSize", MyObservationContext):
webviewHeightConstraint.constant = TextoHtml.scrollView.contentSize.height
super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)

I'm open for suggestions, thanks.


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.