SHARE
TWEET

Swift func with variable number of parameters

applehelpwriter Jun 4th, 2014 222 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //swift
  2.  
  3. //variable number of parameters
  4.  
  5. func sumOf(numbers: Int...) -> Int {
  6.     var sum = 0
  7.     for number in numbers {
  8.     sum += number
  9.     }
  10.     return sum
  11. }
  12.  
  13. sumOf(1,2,3,4,5,6,7,8,9)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top