Skip to content

Instantly share code, notes, and snippets.

@GrfxGuru
Created March 11, 2017 05:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GrfxGuru/bf6920888f4febd6b25479ecd4183add to your computer and use it in GitHub Desktop.
Save GrfxGuru/bf6920888f4febd6b25479ecd4183add to your computer and use it in GitHub Desktop.
Swift Convenience Initializers
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