iOS App launch crash

Just messing around, querying / writing to the database. No crashes with a single UIViewController, or if the offending line is commented out.

In Storyboard, I embedded a Nav Bar controller and more UIViewControllers. If I run the app, tapping on the nav bar items, swaps (segues) to the different UI’s. Everything as expected.


In the 2nd View Controller I added, the app crashes if I declare a class-wide variable as the first thing inside the Swift file. Current (complete) code is:

import UIKit
import Parse

class LeaderViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    var comp = PFObject() // CAUSES APP LAUNCH CRASH... NSInternalInconsistencyException

    override func viewDidLoad() {

        print("viewDidLoad Called")
    override func viewDidAppear(_ animated: Bool) {
        print("viewDidAppear Called")
        let queryComp = PFQuery(className: "Competition")
        queryComp.getObjectInBackground(withId: "CXy40U65Z9") { (compObj, error) in
            if let compObjUnwrap = compObj {
                self.comp = compObjUnwrap
                print("Comp oID: \(self.comp.objectId)")

    // MARK: TableView Deletage Methods
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
        return cell


First line of crash log (can provide more if needed):

2020-08-29 21:11:23.471701+0100 Parse-2[10213:1763803] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Can only call -[PFObject init] on subclasses conforming to PFSubclassing.'

Tracking down the NSInternalInconsistencyException error (StackOverflow thread), I changed:

var comp = PFObject()

To an optional:

var comp: PFObject?

I don’t fully understand why in the main (original) ViewController, I was able to declare the same empty object, but in this 2nd ViewController (different Struct) I have to make it optional, else it crashes…