Short question, I have the following structure, which I store in "Salas"
struct SalasMaster {
let id: Int
let nombre: String
let latitud: String
let longitud: String
let piso: String
let observaciones: String
let pabellon: String
}
var Salas = [SalasMaster]()
...receiving data...
...dump(Salas)
example -> SalasMaster
- id: 307
- nombre: "SALA DE PROYECTOS "
- latitud: "-29.96429300"
- longitud: "-71.34937300"
- piso: "1"
- observaciones: ""
- pabellon: "X - Escuela de Ingeniería"
And finally what I want is to filter the example id, at this moment I get an array where it is, along with all other corresponding data
...filter data...
var arrayFiltered = Salas.filter{$0.id == 307}
Print(arrayFiltered) -> [SalasMaster(id: 307, nombre: "SALA DE PROYECTOS ", latitud: "-29.96429300", longitud: "-71.34937300", piso: "1", observaciones: "", pabellon: "X - Escuela de Ingeniería")]
But I can't find the way to return only one data that I'm interested in retrieving from "id", in this case I want to capture only "latitud", although in another case I might need another one.
You can use
first(where:)
for that because it will give you first matching record and stop searching after it.or if you want to get more than one field that interests you, you could use tuples:
This will map through
Salas
and return an array oflatitud
s.For example