Skip to content

Instantly share code, notes, and snippets.

@khawajafarooq
Created September 28, 2017 04:30
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 khawajafarooq/2e9662a4e189e0282359a0af499db35d to your computer and use it in GitHub Desktop.
Save khawajafarooq/2e9662a4e189e0282359a0af499db35d to your computer and use it in GitHub Desktop.
Underlying concept of reference semantics in swift
class Machine {
let model: String
var make: String
init(model: String, make: String) {
self.model = model
self.make = make
}
}
/// uncomment to check compiler error
var m1 = Machine(model: "USS", make: "M1900")
//m1.model = "RSS"
m1.make = "M2000"
// under the hood reference pointer is updated instead of assigning new value back
let m2 = Machine(model: "USS", make: "M2100")
//m2.model = "RSS"
m2.make = "M2300"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment