1

I use method .keys from the Dictionary to fetch all keys that are in the dictionary and work with them like Array.

Problem when i fetch it .keys it returns LazyMapCollection how i can convert it to Array of keys.

Precondition:

User is structure with funds not nil dictionary [String:String].

let keys = user.funds?.keys

How should i convert keys to be Array?

Oleg Gordiichuk
  • 15,240
  • 7
  • 60
  • 100

1 Answers1

9

Maybe using map will help:

let dictionary: [String:String] = [:]
let keys: [String] = dictionary.map({ $0.key })

Don't like map? Go this way:

let dictionary: [String:String] = [:]
let keys: Array<String> = Array<String>(dictionary.keys)
iWheelBuy
  • 5,470
  • 2
  • 37
  • 71