En Swift 4 podría funcionar el siguiente código, pero en Swift 5 aparece el siguiente error: Type 'Dictionary<String, String>.Values.Iterator' does not conform to protocol 'Sequence'
guard let userIds = users.values.makeIterator() else { return } for userId in userIds { // User setup }¿Cuál es la forma correcta en Swift 5 ahora?
let dictionary: [String: Int] = ["a": 1, "b": 2] for (key, value) in dictionary { print(key, value) }Puedes probar un iterador como este:
let users = ["a":11, "b":12] var userIds = users.values.makeIterator() while let next = userIds.next() { print(next) // 11 \n 12 }También:
let x = [ "kitty": 7, "bob": 2, "orange": 44 ] x.forEach { t in print("key = \(t.key); value = \(t.value)") } Aparentemente, esto ha estado disponible desde Swift 3. Enlace a documentos de biblioteca estándar en tipo Dictionary .