Last active
August 29, 2015 14:14
-
-
Save ChrisLTD/cfcaab2c2225531302e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| class myClass { | |
| var myVal = 1 | |
| } | |
| func addVals(myClasses: [myClass]) -> Int { | |
| var result = 0 | |
| for thisClass in myClasses { | |
| result += thisClass.myVal | |
| } | |
| return result | |
| } | |
| func addValsVariadic(myClasses: myClass...) -> Int { | |
| var result = 0 | |
| for thisClass in myClasses { | |
| result += thisClass.myVal | |
| } | |
| return result | |
| } | |
| let c1 = myClass() | |
| c1.myVal = 2 | |
| let c2 = myClass() | |
| c2.myVal = 3 | |
| addVals([c1, c2]) // returns 5 | |
| addValsVariadic(c1, c2) // also returns 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment