Skip to content

Instantly share code, notes, and snippets.

@luki
Created April 5, 2016 14:46
Show Gist options
  • Save luki/40ee633cdd32210e9e8025d5ab969069 to your computer and use it in GitHub Desktop.
Save luki/40ee633cdd32210e9e8025d5ab969069 to your computer and use it in GitHub Desktop.
A calculator class in Swift.
class Calculator {
let first: Double
let second: Double
init(first: Double, second: Double){
self.first = first
self.second = second
}
func addition() -> Double {
return first + second
}
func subtraction() -> Double {
return first - second
}
func multiplication() -> Double {
return first * second
}
func divison() -> Double {
return first / second
}
}
let calc = Calculator(first: 4, second: 3)
calc.addition()
calc.subtraction()
calc.multiplication()
calc.divison()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment