출처 : http://locomoviles.com/uncategorized/filtering-swift-array-dictionaries-object-property/
배열 검색에 대해서 여러 사이트를 찾아 보았으나 이 사이트가 가장 깔끔하게 정리된 것 같다.
- 그냥 배열일 때
- 딕셔너리 일 때
- 구조체 일 때
To filter a simple swift array you just need to use the “filter” method like below.
The code inside the curly braces is a statement that should return a Boolean to indicate if an item is included or not in the final array. $0 represents an object in an array which is like an object you get out of a for loop.
Filtering an Array of Dictionaries
Filtering dictionaries is easy. In the example code we have an array of age in dictionaries. We want to filter the ages that are below 30.
Filtering an Array of Objects
Same as above we will filter by age but now we will filter objects by its age property.
See how easy it is to filter dictionaries and objects. If you have suggestions or comments please leave some behind.