I wrote the code on the Playground:

import Foundation /* * Игра * Необходимо реализовать игру «Камень-ножница-бумага». * Нужно дать пользователю сыграть против компьютера. * Камень побеждает ножницы, ножницы побеждают бумагу, а бумага побеждает камень. */ func rockPaperScissors() -> Any? { print("Welcome to game 'Rock-Paper-Scissors!'\n") //print("Do u want to play an one part?") //print("Press 'y' to play or 'n' to cancel") //print("***") //let userResponceAboutGame = readLine() print("Choose your item for fight!") print("1: Rock") print("2: Paper") print("3: Scissors") let userResponseAboutItem = Int(readLine()!) var userItem: String? switch userResponseAboutItem! { case 1: userItem = "Rock" case 2: userItem = "Paper" case 3: userItem = "Scissors" default: return nil } let random = Float(arc4random() / UInt32.max) var computerItem: String? if random < 0.33 { computerItem = "Rock" } else if random == 0.33 && random < 0.66 { computerItem = "Paper" } else { computerItem = "Scissors" } print("User's choice: \(userItem)") print("FIGHT!") print("\(userItem) VS ...") print("\(userItem) VS \(computerItem)") if userItem == computerItem { print("Standoff!") } if userItem == "Rock" { if computerItem == "Paper" { print("Computer win!") } else if computerItem == "Scissors" { print("You win!") } } if userItem == "Paper" { if computerItem == "Rock" { print("You win!") } else if computerItem == "Scissors" { print("Computer win!") } } if userItem == "Scissors" { if computerItem == "Rock" { print("Computer win!") } else if computerItem == "Paper" { print("You win!") } } return nil } rockPaperScissors() 

Caused a fatal error in the console:

nil while unwrapping an Optional value

Obviously, some optional variable doesn't get the value. And most likely the problem is in the userResponseAboutItem variable, because the readline() function does not work the way I expect.

Still, how to put a breakpoint in the new Xcode?

I tried:

  1. After selecting a line of code, press the key combination "cmd + \";
  2. Click on the line number of the code.

PS In previous versions of Xcode, it seemed to set breakpoints without problems. Just learning debbagingu. Version Xcode 8.1 (8B62)

UPD: readline() does not work in the Playground, but this does not cancel the question.

    2 answers 2

    There is no debugger and no breakpoint in the playground.

    Regarding your mistake, as far as I understand readline () will not work in the playground.

    Indeed, in cases of console program development, you need to run the project by selecting the Command Line Tool , where readline() will work and process the input values.