diff options
Diffstat (limited to 'zh-cn')
-rw-r--r-- | zh-cn/go-cn.html.markdown | 1 | ||||
-rw-r--r-- | zh-cn/groovy-cn.html.markdown | 4 | ||||
-rw-r--r-- | zh-cn/swift-cn.html.markdown | 30 |
3 files changed, 19 insertions, 16 deletions
diff --git a/zh-cn/go-cn.html.markdown b/zh-cn/go-cn.html.markdown index 75498367..37b4b137 100644 --- a/zh-cn/go-cn.html.markdown +++ b/zh-cn/go-cn.html.markdown @@ -142,6 +142,7 @@ func learnTypes() { func learnNamedReturns(x, y int) (z int) { z = x * y return // z is implicit here, because we named it earlier. +} // Go全面支持垃圾回收。Go有指针,但是不支持指针运算。 // 你会因为空指针而犯错,但是不会因为增加指针而犯错。 diff --git a/zh-cn/groovy-cn.html.markdown b/zh-cn/groovy-cn.html.markdown index 562a0284..0e7a020c 100644 --- a/zh-cn/groovy-cn.html.markdown +++ b/zh-cn/groovy-cn.html.markdown @@ -219,10 +219,12 @@ for (i in array) { //遍历映射 def map = ['name':'Roberto', 'framework':'Grails', 'language':'Groovy'] -x = 0 +x = "" for ( e in map ) { x += e.value + x += " " } +assert x.equals("Roberto Grails Groovy ") /* 运算符 diff --git a/zh-cn/swift-cn.html.markdown b/zh-cn/swift-cn.html.markdown index cba9252d..c25b2918 100644 --- a/zh-cn/swift-cn.html.markdown +++ b/zh-cn/swift-cn.html.markdown @@ -445,47 +445,47 @@ if let circle = myEmptyCircle { // 枚举可以像类一样,拥有方法 enum Suit { - case Spades, Hearts, Diamonds, Clubs + case spades, hearts, diamonds, clubs func getIcon() -> String { switch self { - case .Spades: return "♤" - case .Hearts: return "♡" - case .Diamonds: return "♢" - case .Clubs: return "♧" + case .spades: return "♤" + case .hearts: return "♡" + case .diamonds: return "♢" + case .clubs: return "♧" } } } // 当变量类型明确指定为某个枚举类型时,赋值时可以省略枚举类型 -var suitValue: Suit = .Hearts +var suitValue: Suit = .hearts // 非整型的枚举类型需要在定义时赋值 enum BookName: String { - case John = "John" - case Luke = "Luke" + case john = "John" + case luke = "Luke" } -print("Name: \(BookName.John.rawValue)") +print("Name: \(BookName.john.rawValue)") // 与特定数据类型关联的枚举 enum Furniture { // 和 Int 型数据关联的枚举记录 - case Desk(height: Int) + case desk(height: Int) // 和 String, Int 关联的枚举记录 - case Chair(brand: String, height: Int) + case chair(brand: String, height: Int) func description() -> String { switch self { - case .Desk(let height): + case .desk(let height): return "Desk with \(height) cm" - case .Chair(let brand, let height): + case .chair(let brand, let height): return "Chair of \(brand) with \(height) cm" } } } -var desk: Furniture = .Desk(height: 80) +var desk: Furniture = .desk(height: 80) print(desk.description()) // "Desk with 80 cm" -var chair = Furniture.Chair(brand: "Foo", height: 40) +var chair = Furniture.chair(brand: "Foo", height: 40) print(chair.description()) // "Chair of Foo with 40 cm" |