Is there any way to map dictionary of type [NSString: Any] to another [String: Any]

87 Views Asked by At

I tried to cast dictionary of type [UIImagePickerController.InfoKey: Any] to [String: Any] type, but it seems it's not possible. The result was nil. I've found straightway to iterate throught original dict, grab value and insert it with rawValue. But maybe I'm doing it wrong

debugger showed that [UIImagePickerController.InfoKey: Any] under the hood is [NSString: Any]

let imagePropsDict: [UIImagePickerController.InfoKey: Any] = getStubbedProps()
var propsDict: [String: Any] = [:]
imagePropsDict.forEach { infoKey, value in
    propsDict[infoKey.rawValue] = value
}

and the invalid code:

if let mappedDict = imagePropsDict as? [String: Any] { ... }
0

There are 0 best solutions below