overridefuncviewDidLoad() { super.viewDidLoad() self.navigationItem.title = "协议" protocolsMethod() // Do any additional setup after loading the view. }
overridefuncdidReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. }
classLinearCongruentialGenerator: RandomNumberGenerator{ var lastRandom = 42.0 let m = 13968.0 let a = 3877.0 letc = 29573.0 funcrandom() -> Double { lastRandom = ((lastRandom * a + c) % m) return lastRandom / m } }
classDiceGameTracker: DiceGameDelegate{ var numberOfTurns = 0 funcgameDidStart(game: DiceGame) { numberOfTurns = 0 if game isSnakesAndLadders { println("Started a new game of Snakes and Ladders") } println("The game is using a \(game.dice.sides)") } funcgame(game: DiceGame, didStartNewTurnWithDiceRoll diceRoll: Int) { ++numberOfTurns println("Rolled a \(diceRoll)") } funcgameDidEnd(game: DiceGame) { println("The game lasted for \(numberOfTurns) turns") } }