Language/Swift
Swift - forEach
codinglearn
2020. 6. 29. 11:51
반응형
forEach(_:)
Calls the given closure on each element in the sequence in the same order as a for-inloop.
for-in과 동일하게 사용하는 고차함수
let numberWords = ["one", "two", "three"]
for word in numberWords {
print(word)
}
// Prints "one"
// Prints "two"
// Prints "three"
numberWords.forEach { word in
print(word)
}
// 위와 출력되는 값이 동일하다.
// Prints "one"
// Prints "two"
// Prints "three"
반응형