I got this error in swift3:
Cannot convert value of type [AnyHashable : Any] to type NSDictionary in coercion.
My code is:
func downloadProgress(notification:NSNotification){
if let userInfo = notification.userInfo as NSDictionary
{
print(userInfo)
if let progressValue = userInfo["progressPercentage"] as? Float {
if progressValue > 0.01{
}
}
}
}
The actual value of user information ["progressPercentage": 0.82530790852915281], but it is printed as [AnyHashable("progressPercentage"): 0.82530790852915281]and does not meet the condition if.
Edit:
No luck for notification.userInfo as? [AnyHashable: Any]but now works for notification.userInfo as? [String: AnyObject]andnotification.userInfo as? [String: Any]


source
share