Refactoring to share code

Perform the following steps:

  1. Create a new empty Swift file in our Controllers folder and call it BaseTableViewController.swift.
  2. Inside of our BaseTableViewController.swift file, create a new class that inherits from the UITableViewController and has a requestInput method:
import UIKit class BaseTableViewController: UITableViewController {  func requestInput(title: String, message: String, handler:       @escaping (String) -> ()) {    let alert = UIAlertController(title: title,                                  message: message,                                  preferredStyle: .alert)        alert.addTextField(configurationHandler: nil)        alert.addAction(UIAlertAction(title: "Cancel", style: .cancel,                    handler: nil))        alert.addAction(UIAlertAction(title: "Add", style: .default,  handler: { (_) ...

Get Hands-On Full-Stack Development with Swift 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.