1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| var array = [Int]()
array.reserveCapacity(20)
array.isEmpty
for x in array {}
for x in array.dropFirst() {}
for x in array.dropLast(5) {}
for (index, element) in array.enumerated() {}
if let index = array.firstIndex{ someMatchingLogic($0) } {} if let index = array.lastIndex { someMatchingLogic($0) } {} if let element = array.first { someMatchingLogic($0) } {} if let element = array.last { someMatchingLogic($0) } {} if array.contains { someMatchingLogic($0) } {}
array.map { someTransformation($0) }
let values = [[1,3,5,7],[9]] let flattenResult = values.flatMap{ $0 }
let values:[Int?] = [1,3,5,7,9,nil] let flattenResult = values.flatMap{ $0 }
let words = ["a", "b"] let nums = ["1", "2"] let result = words.flatMap { word in nums.map { num in (word, num) } }
array.forEach { doSomething($0) }
array.allSatisfy {}
array.filter { someCriteria($0) }
array.reduce(0) { total, num in total + num } array.reduce(0, +)
sort(by:)
sorted(by:)
lexicographicallyPrecedes(_:by:)
partition(by:)
min(by:) max(by:)
elementsEqual(_:by:)
starts(with:)
split(whereSeparator:)
prefix(while:)
drop(while:)
removeAll(where:)
let slice = array[1...]
|