Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //: Classes in Swift
- class Cat {
- var name: String
- var color: String
- var weight: Double
- var legs: Int = 4
- init(name: String, color: String, w:Double) {
- self.name = name
- self.color = color
- self.weight = w
- }
- }
- let fluffers = Cat(name: "Fluffers", color: "Black", w: 2.0)
- fluffers.legs = 3
- print(fluffers.legs)
- let mitsy = fluffers
- mitsy.name = "Mitsy"
- print(mitsy.name)
- print(fluffers.name) //uh oh, reference type so fluffers got renamed too.
Add Comment
Please, Sign In to add comment