Variadic functions — swift

print(“apple”,”pineapple”,”orange”)
From Apple docs
func printFruitNames (_ fruits: String...) -> () {for fruit in fruits { // fruits is a string arrayprint(“\(fruit)”)}}printFruitNames(“apple”,”pineapple”,”orange”)
func arithmeticMean(_ numbers: Double...) -> Double {var total: Double = 0for number in numbers {total += number}return total / Double(numbers.count)}arithmeticMean(1, 2, 3, 4, 5)// returns 3.0, which is the arithmetic mean of these five numbersarithmeticMean(3, 8.25, 18.75)// returns 10.0, which is the arithmetic mean of these three numbers

If you enjoyed reading this post, please share and recommend it so others can find it 💚💚💚💚💚💚 !!!!

--

--

--

iOS and tvOS developer, dreamer, photographer 🤨

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhimuralidharan

Abhimuralidharan

iOS and tvOS developer, dreamer, photographer 🤨

More from Medium

MVVM-C Xcode Template to reduce development time

Closures in swift

How to monitor progress of Xcode installation from App Store

Swift ScrollView 自適應高度設定