macOS, iOS

[Swift] Int...같이 swift의 three-dots은 무엇일까

SweetDev 2019. 10. 28. 18:33

 

 

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.

 

 

 

하나 이상의 값이 들어올 수 있다는 것!

 

정말 신기하다...

심지어 배열 형태도 아님.