Skip to content

Instantly share code, notes, and snippets.

@showcove
Created January 8, 2022 02:48
Show Gist options
  • Save showcove/5503bfeb3a215b8314ec4ed7bd911d23 to your computer and use it in GitHub Desktop.
Save showcove/5503bfeb3a215b8314ec4ed7bd911d23 to your computer and use it in GitHub Desktop.
StructVsClass_Playground (1)
import UIKit
struct ModelAsStruct {
var id: Int
var name: String
}
var model1 = ModelAsStruct(id: 1, name: "jay")
var model1Copy = model1
model1Copy.id = 2
model1Copy.name = "garam"
print("model1 :", model1)
print("model1Copy :", model1Copy)
class ModelAsClass: CustomStringConvertible {
var id: Int
var name: String
init(id: Int, name: String) {
self.id = id
self.name = name
}
var description: String {
return "ModelAsClass(id: \(id), name: \(name)"
}
}
var model2 = ModelAsClass(id: 1, name: "jay")
var model2Copy = model2
model2Copy.id = 2
model2Copy.name = "garam"
print("model2 :", model2)
print("model2Copy :", model2Copy)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment