티스토리 뷰
This is what's called a "variadic parameter." It means that the function can take more than one value of that type. The function's block will have access to an array-like structure (I can't remember if it's an actual array or not), which can be iterated on and used to perform some work on all of the members in it.
So in the example you posted, that function can take a variable number of Ints, passed into the numbers parameter. Inside the function, we iterate through numbers and add them all up, and then return the result.
EDIT: It turns out that the parameter is actually an array of the type declared in the parameter list. Also, worth noting is that you can only have one variadic parameter per function, and it has to be the last parameter in the list.
하나 이상의 값이 들어올 수 있다는 것!
정말 신기하다...
심지어 배열 형태도 아님.
'macOS, iOS' 카테고리의 다른 글
xcode에서 미리보기 보기. (0) | 2019.11.06 |
---|---|
[iOS] Operator function '..<' requires that 'Optional<Int>.Stride' conform to 'SignedInteger' (0) | 2019.11.01 |
[Swift] 함수선언에서 _(underbar) (0) | 2019.10.28 |
swift의 defer (0) | 2019.10.28 |
iOS에서 nine patch 하는 법 (0) | 2019.10.22 |