Book Image

Swift Cookbook

By : Cecil Costa, Cecil Costa
Book Image

Swift Cookbook

By: Cecil Costa, Cecil Costa

Overview of this book

Table of Contents (18 chapters)
Swift Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
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...