I'm having a dictionary [String: Any!] that has values like integers, floats and strings. When I'm creating URLComponents using below code, its not taking values related to integers and floats.
func queryItems(dictionary: [String: Any]) -> [URLQueryItem] {
return dictionary.map {
URLQueryItem(name: $0, value: $1 as? String)
}
}
Obviously
Anycould be anything. But if you have some control of your inputs one easy option is casting toLosslessStringConvertible.String,Substringand your basic numeric types all conform to it.Warnings:
Boolreturnstrueorfalse.NSObjectdoes not conform to this, so if you're mixing inNSNumberorNSStringyou need to account for those also.