0
votes

I keep getting the error:

Cannot invoke 'valueForKey' with an argument list of type '(anyObject?)'

when I attempt to convert:

NSError* error = [notification.userInfo valueForKey:ZDA_WEB_VIEW_FAILED_ERROR];

from Objective-C to Swift. My best attempt has been the following Swift code:

var error: NSError = notification.userInfo.valueForKey(ZDA_WEB_VIEW_FAILED_ERROR)

but this doesn't seem to work. Any help will go a long way, thanks!

1

1 Answers

0
votes

You are getting the error because notification.userInfo returns an optional which must be unwrapped. The Swift way to do this would be:

if let error = notification.userInfo?[ZDA_WEB_VIEW_FAILED_ERROR] as? NSError {
    // use error
}