Skip to content

Instantly share code, notes, and snippets.

@meech-ward
Created October 31, 2016 17:28
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 meech-ward/1e56704324693c60f4688ca2ade827c3 to your computer and use it in GitHub Desktop.
Save meech-ward/1e56704324693c60f4688ca2ade827c3 to your computer and use it in GitHub Desktop.
var thermometerStruct1 = ThermometerStruct()
thermometerStruct1.register(temperature: 56.0)
var thermometerStruct2 = thermometerStruct1
thermometerStruct2.register(temperature: 42.0)

var thermometerObject1 = ThermometerClass()
thermometerObject1.register(temperature: 56.0)
var thermometerObject2 = thermometerObject1
thermometerObject2.register(temperature: 42.0)

thermometerStruct1.temperature // 56
thermometerStruct2.temperature // 42

thermometerObject1.temperature // 42
thermometerObject2.temperature // 42

Explain whats going on here. Why do the end values differ between objects and Structs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment