Skip to content

Instantly share code, notes, and snippets.

@fitomad
Created January 21, 2019 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fitomad/5f1a152f609e998398756e806b5ff876 to your computer and use it in GitHub Desktop.
Save fitomad/5f1a152f609e998398756e806b5ff876 to your computer and use it in GitHub Desktop.
let usuarios = [
"Adolfo" : "43",
"Carlos" : "10",
"Hugo" : "9"
]
print(usuario)
// La salida del terminal es...
// ["Hugo": "9", "Carlos": "10", "Adolfo": "43"]
// Ahora cambiamos el diccionario para que
// los valores sean `Int` y no `String`
let edades = usuarios.compactMapValues({ Int($0)})
print("Edades: \(edades)")
// La salida del terminal es...
// Edades: ["Hugo": 9, "Carlos": 10, "Adolfo": 43]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment