0

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
  • 14,647
  • 5
  • 57
  • 94

1 Answers1

8

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,100
  • 2
  • 32
  • 68