Book Image

Swift Cookbook

Book Image

Swift Cookbook

Overview of this book

If you are an experienced Objective-C programmer and are looking for quick solutions to many different coding tasks in Swift, then this book is for you. You are expected to have development experience, though not necessarily with Swift.
Table of Contents (13 chapters)
12
Index

Replacing the UI classes


At this moment, you know how to migrate the model part of an application. However, in real life, we also have to replace the graphical classes. Doing this is not complicated, but this could include a bit full of details.

Getting ready

Continuing with the previous recipe, make a copy of it or just commit the changes you have and let's continue with our migration.

How to do it...

Now, follow these steps to replace the UI classes:

  1. First, create a new file called MainViewController.swift and start importing UIKit:

    import UIKit
  2. The next step is to create a class called MainViewController. This class must inherit from UIViewController and implement the UITableViewDataSource and UITableViewDelegate protocols:

    class MainViewController:UIViewController,UITableViewDataSource, UITableViewDelegate {
  3. Then, add the attributes we had in the previous view controller. Keep the same name you used before:

        private var vehicles = [Car]()
        @IBOutlet var tableView:UITableView!
  4. Next, we need...