Adding a few touches

Although a few things are still missing, either some parts of them are straightforward or we already implemented them in the previous chapters when we were building Flappy Swift.

The score

The score falls under the straightforward category, and it is worth implement it right now so that we can finish adding all the visual elements to the screen.

The goal of the game is for the player to keep going as long as they can without colliding with a cube. So, to implement the score, we just need to schedule a timer that fires every second, increasing the score. First of all, we need to add elements as properties:

class GameViewController: UIViewController { //... private var laneTimer: NSTimer! private let scoreLbl = UILabel() private ...

Get Swift: Developing iOS Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.