objective c - How to get objects from array of objects for given key -
i rows database array. , example have in these rows fields ´id´,´section´. possible id´s chosen section array without loops using operators? instance
1 2 b 2 3 4 b
and section 'a' i'd [1,2,3]
if database array
of tuples
can this:
let database: [(int, string)] = [(1, "a"), (2, "b"), (2, "a"), (3, "a"), (4, "b")] let anumbers = database.filter{ $0.1 == "a" }.map{ $0.0 }
or swift 2:
let anumbers = database.flatmap{ $0.1 == "a" ? $0.0 : nil }
Comments
Post a Comment