更新示例代码 println() -> print()

This commit is contained in:
futantan
2015-06-29 19:02:28 +08:00
parent 42a3b6a739
commit cf3676cd84

View File

@ -164,9 +164,9 @@ class LinearCongruentialGenerator: RandomNumberGenerator {
} }
} }
let generator = LinearCongruentialGenerator() let generator = LinearCongruentialGenerator()
println("Here's a random number: \(generator.random())") print("Here's a random number: \(generator.random())")
// 输出 : "Here's a random number: 0.37464991998171" // 输出 : "Here's a random number: 0.37464991998171"
println("And another one: \(generator.random())") print("And another one: \(generator.random())")
// 输出 : "And another one: 0.729023776863283" // 输出 : "And another one: 0.729023776863283"
``` ```
@ -314,7 +314,7 @@ class Dice {
```swift ```swift
var d6 = Dice(sides: 6,generator: LinearCongruentialGenerator()) var d6 = Dice(sides: 6,generator: LinearCongruentialGenerator())
for _ in 1...5 { for _ in 1...5 {
println("Random dice roll is \(d6.roll())") print("Random dice roll is \(d6.roll())")
} }
//输出结果 //输出结果
//Random dice roll is 3 //Random dice roll is 3
@ -403,16 +403,16 @@ class DiceGameTracker: DiceGameDelegate {
func gameDidStart(game: DiceGame) { func gameDidStart(game: DiceGame) {
numberOfTurns = 0 numberOfTurns = 0
if game is SnakesAndLadders { if game is SnakesAndLadders {
println("Started a new game of Snakes and Ladders") print("Started a new game of Snakes and Ladders")
} }
println("The game is using a \(game.dice.sides)-sided dice") print("The game is using a \(game.dice.sides)-sided dice")
} }
func game(game: DiceGame, didStartNewTurnWithDiceRoll diceRoll: Int) { func game(game: DiceGame, didStartNewTurnWithDiceRoll diceRoll: Int) {
++numberOfTurns ++numberOfTurns
println("Rolled a \(diceRoll)") print("Rolled a \(diceRoll)")
} }
func gameDidEnd(game: DiceGame) { func gameDidEnd(game: DiceGame) {
println("The game lasted for \(numberOfTurns) turns") print("The game lasted for \(numberOfTurns) turns")
} }
} }
``` ```
@ -468,7 +468,7 @@ extension Dice: TextRepresentable {
```swift ```swift
let d12 = Dice(sides: 12,generator: LinearCongruentialGenerator()) let d12 = Dice(sides: 12,generator: LinearCongruentialGenerator())
println(d12.asText()) print(d12.asText())
// 输出 "A 12-sided dice" // 输出 "A 12-sided dice"
``` ```
@ -480,7 +480,7 @@ extension SnakesAndLadders: TextRepresentable {
return "A game of Snakes and Ladders with \(finalSquare) squares" return "A game of Snakes and Ladders with \(finalSquare) squares"
} }
} }
println(game.asText()) print(game.asText())
// 输出 "A game of Snakes and Ladders with 25 squares" // 输出 "A game of Snakes and Ladders with 25 squares"
``` ```
@ -504,7 +504,7 @@ extension Hamster: TextRepresentable {}
```swift ```swift
let simonTheHamster = Hamster(name: "Simon") let simonTheHamster = Hamster(name: "Simon")
let somethingTextRepresentable: TextRepresentable = simonTheHamster let somethingTextRepresentable: TextRepresentable = simonTheHamster
println(somethingTextRepresentable.asText()) print(somethingTextRepresentable.asText())
// 输出 "A hamster named Simon" // 输出 "A hamster named Simon"
``` ```
@ -523,7 +523,7 @@ let things: [TextRepresentable] = [game,d12,simonTheHamster]
```swift ```swift
for thing in things { for thing in things {
println(thing.asText()) print(thing.asText())
} }
// A game of Snakes and Ladders with 25 squares // A game of Snakes and Ladders with 25 squares
// A 12-sided dice // A 12-sided dice
@ -583,7 +583,7 @@ extension SnakesAndLadders: PrettyTextRepresentable {
任意`SankesAndLadders`的实例都可以使用`asPrettyText()`方法。 任意`SankesAndLadders`的实例都可以使用`asPrettyText()`方法。
```swift ```swift
println(game.asPrettyText()) print(game.asPrettyText())
// A game of Snakes and Ladders with 25 squares: // A game of Snakes and Ladders with 25 squares:
// ○ ○ ▲ ○ ○ ▲ ○ ○ ▲ ▲ ○ ○ ○ ▼ ○ ○ ○ ○ ▼ ○ ○ ▼ ○ ▼ ○ // ○ ○ ▲ ○ ○ ▲ ○ ○ ▲ ▲ ○ ○ ○ ▼ ○ ○ ○ ○ ▼ ○ ○ ▼ ○ ▼ ○
``` ```
@ -624,7 +624,7 @@ struct Person: Named, Aged {
var age: Int var age: Int
} }
func wishHappyBirthday(celebrator: protocol<Named, Aged>) { func wishHappyBirthday(celebrator: protocol<Named, Aged>) {
println("Happy birthday \(celebrator.name) - you're \(celebrator.age)!") print("Happy birthday \(celebrator.name) - you're \(celebrator.age)!")
} }
let birthdayPerson = Person(name: "Malcolm", age: 21) let birthdayPerson = Person(name: "Malcolm", age: 21)
wishHappyBirthday(birthdayPerson) wishHappyBirthday(birthdayPerson)
@ -697,9 +697,9 @@ let objects: [AnyObject] = [
```swift ```swift
for object in objects { for object in objects {
if let objectWithArea = object as? HasArea { if let objectWithArea = object as? HasArea {
println("Area is \(objectWithArea.area)") print("Area is \(objectWithArea.area)")
} else { } else {
println("Something that doesn't have an area") print("Something that doesn't have an area")
} }
} }
// Area is 12.5663708 // Area is 12.5663708
@ -776,7 +776,7 @@ var counter = Counter()
counter.dataSource = ThreeSource() counter.dataSource = ThreeSource()
for _ in 1...4 { for _ in 1...4 {
counter.increment() counter.increment()
println(counter.count) print(counter.count)
} }
// 3 // 3
// 6 // 6
@ -807,7 +807,7 @@ counter.count = -4
counter.dataSource = TowardsZeroSource() counter.dataSource = TowardsZeroSource()
for _ in 1...5 { for _ in 1...5 {
counter.increment() counter.increment()
println(counter.count) print(counter.count)
} }
// -3 // -3
// -2 // -2