Placing Each Block

You want to place one block at a time in a loop. You get a random direction by creating an enumeration of different directions. To make this happen, place this code above your viewDidLoad function, inside the game class:

enum BlockDirection {    case Left, Right, Front, Back, Top    static func getRandomDirection() -> BlockDirection {        var directions = [Left,Right,Front,Back,Top]        var range = UInt32(0)..<UInt32(directions.count - 1)        return directions[Int(range.startIndex + arc4random_uniform(range.endIndex -           range.startIndex + 1))]    }}

This enumeration contains all the different directions in which you could place a block. You are placing a block in reference to the ...

Get Learning Swift™ Programming 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.