Adding a UI to the Bingo Machine

  1. Create a new Project using the iOS Single View Application template
  2. Set the language to Swift, and the User Interface to Storyboard. Name the product something like BingoCaller
  3. Click on the project name in the project navigator, and under deployment info, ensure only the landscape options are checked.
  4. Add the BingoMachine.swift file you created previously to the project, either by dragging them into your project, or by using the menu option File -> Add files to BingoCaller, ensuring you select the checkboxes as shown below: Dialogue box showing how to copy items to destination
  5. Open the storyboard and with the ViewController selected, at the bottom of the window, set the size to the smallest iPad and the orientation to landscape.
  6. Towards the right hand side of the view, add a label and two buttons, Set the label to display two dashes, centre its text and enlarge the font. Ensure it has enough space to display 2 numbers. Set the button titles to 'Reset' and 'Call'.
  7. Connect up the label as an outlet named calledNumber.
  8. Connect the buttons up as actions named "callNumberPressed" and "resetPressed" appropriately. ViewController's interface will now contain code similar to that shown below
    @IBOutlet weak var calledNumber: UILabel!
        
    @IBAction func resetPressed(sender: AnyObject) {
    }
        
    @IBAction func callNumberPressed(sender: AnyObject) {
    }
  9. In the ViewController class (outside any of it's functions), add the following to create a BingoMachine:
    var bingoMachine = BingoMachine()
  10. Inside the callNumberPressed method, add the following code to get a number from the bingo machine and display it in the calledNumber label:
    let ballNumber = bingoMachine.getNumber()
    calledNumber.text = String(ballNumber)
  11. Run the application and you should be able to call 90 numbers, although if you call the 91st number the application will crash.
  12. Add code inside the callNumberPressed method to only call the number if there are balls remaining.
  13. Finally, add code to reset the Bingo machine if the reset button is pressed. This should be as simple as re-initialising the bingoMachine variable.