You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesi贸n a prueba de IA

Antes: $249

Currency
$209
Suscr铆bete

Termina en:

1 D铆as
2 Hrs
25 Min
27 Seg

Iteraci贸n en diccionarios

21/33
Resources

Contributions 4

Questions 0

Sort by:

Want to see more contributions, questions and answers from the community?

Se pueden tener tanto el key como el valor en una variable y ordenarlas indistintamente atraves del del key o del valor usando tuplas

var namesOfInt = Dictionary<Int,String>()
namesOfInt = [3:"XD"]
namesOfInt[4] = "Hola"
typealias Tupla = ( key : Int , value: String )
var dicionario = Array<Tupla>(namesOfInt)
print(dicionario.sorted(by: {$0.key > $1.key}))
print(dicionario.sorted(by: {$0.value > $1.value}))

Para ordernar (sortear) los diccionarios:

import UIKit

let paises: [String: String] = [
    "MX": "M茅xico",
    "US": "Unitated States",
    "CO": "Colombia"
]

print("Diccionario sorteado por claves:")
print(paises.keys.sorted(by: <))

print("")

print("Diccionario sorteado por valores:")
print(paises.values.sorted(by: <))
// si necesito que las claves o valores de un diccionario est茅n en arrays:
var AirportsValues = [String](airports.values)

// si necesito que las claves o valores de un diccionario est茅n en arrays:
var AirportKeys = [String](airports.keys)

// 猬嗭笍 se pueden ordenar con sorted 馃槃