"Invalid parameter not satisfying: [constraint isKindOfClass:[NSLayoutConstraint class]]"

I am learning Xcode from a book 'iOS Programming for Beginners' and although I am sure I entered the text correctly I get the following error when I click on the Location button. The code builds with out error, so I don't know where the error is!
Here is the code:
Code Block
//
//  LocationViewController.swift
//  LetsEat3
//
//  Created by Tony Hudson on 27/04/2021.
//
import UIKit
class LocationViewController: UIViewController, UITableViewDataSource {
    @IBOutlet weak var tableView: UITableView!
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        10
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "locationCell", for: indexPath)
        cell.textLabel?.text = "A Cell"
        return cell
    }
}

cal=n anyone explain why I get this error?

Accepted Reply

I have abandoned this version of the project as an error occurred saying it could not connect to my profile as it was missing, so I uninstalled Xcode and reinstalled.

Replies

I believe that the error started when the class was first formed. The class 'LocationViewController' was created in the Location folder by creating a new Cocoa Touch file in the Location folder, then Ctrl + dragging from the table view in the scene. this produced an outlet which was named 'tableView'. Then the 'Datasource & Delegate' outlets were formed by dragging from the connection view 'Datasource & Delegate' to the LocationViewController. after a bit of coding, the following code is tested:
Code Block
//
//  LocationViewController.swift
//  LetsEat3
//
//  Created by Tony Hudson on 27/04/2021.
//
import UIKit
class LocationViewController: UIViewController, UITableViewDataSource {
    
    @IBOutlet weak var tableView: UITableView!
    let manager = LocationDataManager()
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
       10
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "locationCell", for: indexPath)
        cell.textLabel?.text = "A Cell"
        return cell
    }
  The code builds OK, but fails when I click on the Location button.
It seems to suggest that there is a layout error, but I have checked for in consistencies  but there are none.
Does this make the solving of this problem any easier?
}

Still can't solve this error!
As far as I can see there are no constraint errors, as there is not a warning triangle showing on the scene.
Here is more detail of the error:
Code Block
libsystem_kernel.dylib`__pthread_kill:
    0x1bd7c3e38 <+0>:  mov    x16, #0x148
    0x1bd7c3e3c <+4>:  svc    #0x80
->  0x1bd7c3e40 <+8>:  b.lo   0x1bd7c3e5c               ; <+36>
    0x1bd7c3e44 <+12>: stp    x29, x30, [sp, #-0x10]!
    0x1bd7c3e48 <+16>: mov    x29, sp
    0x1bd7c3e4c <+20>: bl     0x1bd7bce10               ; cerror_nocancel
    0x1bd7c3e50 <+24>: mov    sp, x29
    0x1bd7c3e54 <+28>: ldp    x29, x30, [sp], #0x10
    0x1bd7c3e58 <+32>: ret    
    0x1bd7c3e5c <+36>: ret    

What does the +36 mean, which is on the line with the error?
You speak of a Location button.
You do not show its IBAction.

In addition, LocationViewController should also conform to UITableViewDelegate

'Datasource & Delegate' outlets were formed by dragging from the connection view 'Datasource & Delegate' to the LocationViewController

This is not very clear.
You'd better set the delegate in viewDidLoad

Code Block
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
}

So please provide more comprehensive code so that we can find what is happening.

Code Block
import UIKit
class LocationViewController: UIViewController, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
let manager = LocationDataManager()
override func viewDidLoad() {
super.viewDidLoad()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
10
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "locationCell", for: indexPath)
cell.textLabel?.text = "A Cell"
return cell
}
}

Finally, do an option-clean build folder, as it seems you have moved things around.
I have abandoned this version of the project as an error occurred saying it could not connect to my profile as it was missing, so I uninstalled Xcode and reinstalled.