Guest User

Untitled

a guest
Mar 18th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. //: Classes in Swift
  2.  
  3. class Cat {
  4.  
  5. var name: String
  6. var color: String
  7. var weight: Double
  8.  
  9. var legs: Int = 4
  10.  
  11. init(name: String, color: String, w:Double) {
  12. self.name = name
  13. self.color = color
  14. self.weight = w
  15. }
  16.  
  17. }
  18.  
  19.  
  20. let fluffers = Cat(name: "Fluffers", color: "Black", w: 2.0)
  21. fluffers.legs = 3
  22. print(fluffers.legs)
  23.  
  24. let mitsy = fluffers
  25. mitsy.name = "Mitsy"
  26. print(mitsy.name)
  27. print(fluffers.name) //uh oh, reference type so fluffers got renamed too.
Add Comment
Please, Sign In to add comment