728x90
append(_:) vs append(contentsOf:)
- append : 하나의 element를 배열 맨 뒤에 추가해준다
var numbers = [1, 2, 3, 4, 5]
numbers.append(100)
print(numbers)
// Prints "[1, 2, 3, 4, 5, 100]"
- append(contentsOf): 여러개의 elements를 배열 맨 뒤에 추가 해준다.
var numbers = [1, 2, 3, 4, 5]
numbers.append(contentsOf: 10...15)
print(numbers)
// Prints "[1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15]"
출처 :
https://developer.apple.com/documentation/swift/array/append(_:)-1ytnt
https://developer.apple.com/documentation/swift/array/append(contentsof:)-21slv
728x90
'iOS > swift' 카테고리의 다른 글
숫자 다루기 (0) | 2023.11.07 |
---|---|
attributedString (0) | 2022.12.26 |
String (0) | 2022.09.22 |
진법 변환 (0) | 2022.08.31 |
Alamofire timeout set(Swift5) (0) | 2022.08.25 |
댓글