- Map: Transform the array contents.
- Reduce: Reduce the values in the collection to a single value.
- Sort: Sorting the arrays.
- Filter: Transform the array contents.
map(_:)
Returns an array containing the results of mapping the given closure over the sequence’s elements.
let cast = ["Vivien", "Marlon", "Kim", "Karl"]
let lowercaseNames = cast.map { $0.lowercased() }
// 'lowercaseNames' == ["vivien", "marlon", "kim", "karl"]
let letterCounts = cast.map { $0.count }
// 'letterCounts' == [6, 6, 3, 4]
reduce(_:_:)
Returns the result of combining the elements of the sequence using the given closure.
let numbers = [1, 2, 3, 4]
let numberSum = numbers.reduce(0, { x, y in
x + y
})
// numberSum == 10
sort()
Sorts the collection in place.
var students = ["Kofi", "Abena", "Peter", "Kweku", "Akosua"]
students.sort()
print(students)
// Prints "["Abena", "Akosua", "Kofi", "Kweku", "Peter"]"
'ios개발 > 개념 정리' 카테고리의 다른 글
<아키텍처> data driven programming vs data oriented design (0) | 2020.10.07 |
---|---|
<스위프트> Custom Operator, Generic, inout parameter (0) | 2020.04.09 |
<ios framework> present 2편 (0) | 2020.03.31 |
<Mac OS> About Multitasking on the Mac OS (0) | 2020.03.29 |
<스위프트> 오퍼레이션과 오퍼레이션큐를 통한 병행성 작업 방식으로 반응형 인터페이스를 구현하자. (0) | 2020.03.25 |