Skip to content

Instantly share code, notes, and snippets.

@agoiabel
Last active January 12, 2018 07:18
Show Gist options
  • Save agoiabel/018bd16c230b7873158b96970f921657 to your computer and use it in GitHub Desktop.
Save agoiabel/018bd16c230b7873158b96970f921657 to your computer and use it in GitHub Desktop.
class Person {
var name: String
var gender: String = "Male"
init(name: String) {
self.name = name
}
}
class Foreigner: Person {
var country: String
init(name: String, country: String) {
super.init(name: name) //use to set the superclass initializer
//change the default gender property
self.gender = "Female"
self.country = country
}
}
var newForeigner: Foreigner = Foreigner(name: "Johndoe", country: "Canada")
newForeigner.gender //will return Female since we already changed it in the init method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment