Skip to content

Instantly share code, notes, and snippets.

@clarkeben
Last active August 22, 2023 14:27
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 clarkeben/ae0417583fea643b77436f9e8a0e34ab to your computer and use it in GitHub Desktop.
Save clarkeben/ae0417583fea643b77436f9e8a0e34ab to your computer and use it in GitHub Desktop.
Self Vs. self
struct LegoCar {
var color: UIColor
var wheels: Int
mutating func addNewWheels(wheels: Int) {
self.wheels = wheels // Using 'self' to refer to this specific Lego car
}
}
var newCar = LegoCar(color: .blue, wheels: 2)
newCar.addNewWheels(wheels: 4)
struct LegoCar {
static var defaultColour: UIColor = .red
static var defaultWheels = 4
var colour: UIColor
var wheels: Int
static func create() -> Self {
return self.init(colour: defaultColour, wheels: defaultWheels)
}
}
let newBuild = LegoCar.create()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment