fork download
  1.  
  2. struct Car {
  3. var name: String
  4. let model: String
  5. let color: String
  6. }
  7.  
  8. // We declared `ford` instance using `let` (immutable now) i.e we are not gonna change its content
  9. let ford = Car(name: "Ford", model: "2010", color: "Red")
  10.  
  11. // Ford instance being copied by ferrari i.e ferrari and ford have two different copies
  12. // We declared `ferrari` instance using `var` (mutable now). In Struct, it always behaves like immutability so we have to declare his instance (i.e ferrari) and variable (i.e name) using `var` only to get mutable behavior
  13.  
  14. var ferrari = ford
  15.  
  16. ferrari.name = "Ferrari"
  17.  
  18. print(ford.name) // Output: Ford
  19. print(ferrari.name) // Output: Ferrari
  20.  
  21.  
  22.  
Success #stdin #stdout 0s 57640KB
stdin
Standard input is empty
stdout
Ford
Ferrari