1

I’m trying to implement the TableView example from Chapter 5 in Swift Programming in Easy Steps exercise. I have checked and re-checked the example code (even downloaded and tested the actual example code), but I’m still getting this runtime error. Anyone know why this is happening?

2019-11-01 07:56:51.247052+0100 TableView_EasySteps[2067:39485] Can't end BackgroundTask: no background task exists with identifier 1 (0x1), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.

here is the ViewController code:

import UIKit

class WebsitesTableViewController: UITableViewController {

    var websites:[[String]] = [
        ["Apple",           "https://www.apple.com"]   ,
        ["NY Times",        "https://www.nytimes.com"] ,
        ["DN",              "https://www.dn.se"]   ,
        ["NFL",             "https://www.nfl.com"]   ,
        ["Premier League",  "https://www.premierleague.com"]   ,
        ["The Guardian",    "https://www.theguardian.com"]
    ]

    override func viewDidLoad() {
        super.viewDidLoad()

        // preserve selection between presentations
        self.clearsSelectionOnViewWillAppear = false
    }

    // MARK: - Table view data source

    override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return websites.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: "cellIdentifier")
        if cell == nil {
            cell = UITableViewCell(style: .subtitle, reuseIdentifier: "cellIdentifier")
        }
        cell!.textLabel!.text = websites[indexPath.row][0]
        cell!.detailTextLabel!.text = websites[indexPath.row][1]

        return cell!
    }

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if let url = URL(string: websites[indexPath.row][1]) {
            UIApplication.shared.open(url)
        }
    }

    // Override to support editing the table view.
    override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
        if editingStyle == .delete {
            websites.remove(at: indexPath.row)
            // Delete the row from the data source
            tableView.deleteRows(at: [indexPath], with: .fade)
        }
    }
}
JMBaker
  • 502
  • 3
  • 7

1 Answers1

0

Check the SceneDelegate.swift file and make sure it's part of the Control files if you're using MVC standard otherwise just make sure that it's part of the files in your Xcode project alongside the AppDelegate.swift and the ViewController.swift amongst others.

  • I'm getting this error too. I'm not using SceneDelegate.swift and I don't even know what MVC is. Do you mean Model-View-Controller framework? – daniel Jan 17 '20 at 21:13
  • yes, by MVC I mean Model-View-Controller framework. Alright, but does your Xcode project have any file with the name SceneDelegate.swift inside it? If it does then I'm sure there has been a change within that file. Kindly check and undo the change, you'll be fine. – Joel Codjoe Jan 20 '20 at 11:25
  • OK. I'll do that. Thank you. – daniel Jan 20 '20 at 12:39