标签:code var func class turn 枚举 结构 name oca
类的初探
class Person{ var firstName: String var lastName: String init(firstName:String, lastName:String) { self.firstName = firstName self.lastName = lastName } func out() -> String { return self.firstName + self.lastName } func goEast() { self.firstName += "aaa" } } let person = Person(firstName: "1", lastName: "2") person.out() person.firstName = "3"; let person2 = person person2.goEast() person2.out() person === person2/*引用同一块地址*/ struct Location{ var x = 0.0 var y = 0.0 func out() -> Float { return Float(x + y); } } //值类型 方法改变自身,需声明关键字mutating //结构体 struct Location2{ var x = 0 var y = 0 mutating func goEast() { self.x += 1 } } //枚举 enum Switch{ case On case Off mutating func click() { switch self { case .On: self = .Off case .Off: self = .On } } } var button = Switch.Off button.click()
标签:code var func class turn 枚举 结构 name oca
原文地址:http://www.cnblogs.com/liuguan/p/7514135.html