Last active
June 1, 2020 06:38
-
-
Save jamesrochabrun/4df6e7e71629e71ca67ad87d2d298b3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//reference types | |
class someClass { | |
var name: String | |
init(name: String) { | |
self.name = name | |
} | |
} | |
var aClass = someClass(name: "James") | |
var bClass = aClass | |
bClass.name = "Sasha" | |
print(aClass.name) // "Sasha" | |
print(bClass.name) // "Sasha" | |
//value types | |
struct SomeStruct { | |
var name: String | |
init(name: String) { | |
self.name = name | |
} | |
} | |
var aStruct = SomeStruct(name: "James") | |
var bStruct = aStruct | |
bStruct.name = "Sasha" | |
print(aStruct.name) // "James" | |
print(bStruct.name) // "Sasha" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
helpful to understand reference and value types in swift.