Book Image

Swift by Example

By : Giordano Scalzo
Book Image

Swift by Example

By: Giordano Scalzo

Overview of this book

Table of Contents (15 chapters)

The game screen


Before implementing the game, let's proceed to build the layout of the cards on the table.

The structure

After creating the MemoryViewController file, we add the class life cycle functions:

class MemoryViewController: UIViewController {
        private let difficulty: Difficulty

    init(difficulty: Difficulty) {
        self.difficulty = difficulty
        super.init(nibName: nil, bundle: nil)
    }
    
    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    deinit{
        println("deinit")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setup()
    }
}
// MARK: Setup
private extension MemoryViewController {
    func setup() {
        view.backgroundColor = UIColor.greenSea()
    }
}

Besides the initializer that accepts the chosen difficulty, although it's not used, we need to add the required initializer with NSCoder. Moreover, you should note that we need to call the parent...