Created
March 11, 2017 05:26
-
-
Save GrfxGuru/bf6920888f4febd6b25479ecd4183add to your computer and use it in GitHub Desktop.
Swift Convenience Initializers
This file contains 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
class Human { | |
var arms: Int | |
var legs: Int | |
var ears: Int | |
init(arms: Int, legs: Int, ears: Int) { | |
self.arms = arms | |
self.legs = legs | |
self.ears = ears | |
} | |
convenience init() { | |
self.init(arms: 2, legs: 2, ears: 2) | |
} | |
} | |
var ken = Human(arms: 2, legs: 2, ears: 2) | |
var tom = Human() | |
print(ken.arms) | |
print(tom.legs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment