1

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)
    }
}
Ahmad F
  • 26,570
  • 13
  • 76
  • 124
Satyam
  • 14,636
  • 29
  • 122
  • 234

1 Answers1

0

I think you should consider using [String:String] instead of [String:Any] and convert your values to String one step before sending it to queryItems function.But if you want to leave it like this than casting from value Int,Float,Double with as? String always fails. you can use String().

Marat Ibragimov
  • 1,006
  • 7
  • 7