更新示例代码 println() -> print()
This commit is contained in:
@ -164,9 +164,9 @@ class LinearCongruentialGenerator: RandomNumberGenerator {
|
||||
}
|
||||
}
|
||||
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"
|
||||
println("And another one: \(generator.random())")
|
||||
print("And another one: \(generator.random())")
|
||||
// 输出 : "And another one: 0.729023776863283"
|
||||
```
|
||||
|
||||
@ -314,7 +314,7 @@ class Dice {
|
||||
```swift
|
||||
var d6 = Dice(sides: 6,generator: LinearCongruentialGenerator())
|
||||
for _ in 1...5 {
|
||||
println("Random dice roll is \(d6.roll())")
|
||||
print("Random dice roll is \(d6.roll())")
|
||||
}
|
||||
//输出结果
|
||||
//Random dice roll is 3
|
||||
@ -403,16 +403,16 @@ class DiceGameTracker: DiceGameDelegate {
|
||||
func gameDidStart(game: DiceGame) {
|
||||
numberOfTurns = 0
|
||||
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) {
|
||||
++numberOfTurns
|
||||
println("Rolled a \(diceRoll)")
|
||||
print("Rolled a \(diceRoll)")
|
||||
}
|
||||
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
|
||||
let d12 = Dice(sides: 12,generator: LinearCongruentialGenerator())
|
||||
println(d12.asText())
|
||||
print(d12.asText())
|
||||
// 输出 "A 12-sided dice"
|
||||
```
|
||||
|
||||
@ -480,7 +480,7 @@ extension SnakesAndLadders: TextRepresentable {
|
||||
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"
|
||||
```
|
||||
|
||||
@ -504,7 +504,7 @@ extension Hamster: TextRepresentable {}
|
||||
```swift
|
||||
let simonTheHamster = Hamster(name: "Simon")
|
||||
let somethingTextRepresentable: TextRepresentable = simonTheHamster
|
||||
println(somethingTextRepresentable.asText())
|
||||
print(somethingTextRepresentable.asText())
|
||||
// 输出 "A hamster named Simon"
|
||||
```
|
||||
|
||||
@ -523,7 +523,7 @@ let things: [TextRepresentable] = [game,d12,simonTheHamster]
|
||||
|
||||
```swift
|
||||
for thing in things {
|
||||
println(thing.asText())
|
||||
print(thing.asText())
|
||||
}
|
||||
// A game of Snakes and Ladders with 25 squares
|
||||
// A 12-sided dice
|
||||
@ -583,7 +583,7 @@ extension SnakesAndLadders: PrettyTextRepresentable {
|
||||
任意`SankesAndLadders`的实例都可以使用`asPrettyText()`方法。
|
||||
|
||||
```swift
|
||||
println(game.asPrettyText())
|
||||
print(game.asPrettyText())
|
||||
// A game of Snakes and Ladders with 25 squares:
|
||||
// ○ ○ ▲ ○ ○ ▲ ○ ○ ▲ ▲ ○ ○ ○ ▼ ○ ○ ○ ○ ▼ ○ ○ ▼ ○ ▼ ○
|
||||
```
|
||||
@ -624,7 +624,7 @@ struct Person: Named, Aged {
|
||||
var age: Int
|
||||
}
|
||||
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)
|
||||
wishHappyBirthday(birthdayPerson)
|
||||
@ -697,9 +697,9 @@ let objects: [AnyObject] = [
|
||||
```swift
|
||||
for object in objects {
|
||||
if let objectWithArea = object as? HasArea {
|
||||
println("Area is \(objectWithArea.area)")
|
||||
print("Area is \(objectWithArea.area)")
|
||||
} else {
|
||||
println("Something that doesn't have an area")
|
||||
print("Something that doesn't have an area")
|
||||
}
|
||||
}
|
||||
// Area is 12.5663708
|
||||
@ -776,7 +776,7 @@ var counter = Counter()
|
||||
counter.dataSource = ThreeSource()
|
||||
for _ in 1...4 {
|
||||
counter.increment()
|
||||
println(counter.count)
|
||||
print(counter.count)
|
||||
}
|
||||
// 3
|
||||
// 6
|
||||
@ -807,7 +807,7 @@ counter.count = -4
|
||||
counter.dataSource = TowardsZeroSource()
|
||||
for _ in 1...5 {
|
||||
counter.increment()
|
||||
println(counter.count)
|
||||
print(counter.count)
|
||||
}
|
||||
// -3
|
||||
// -2
|
||||
|
||||
Reference in New Issue
Block a user