3

I am new to Swift , I am parsing my JSON by using ObjectMapper but I want data to be displayed in TableView. But I have a problem:

libc++abi.dylib: terminating with uncaught exception of type NSException

I get it after the method numberOfRowsInSection. My array is not nil, array has a 2193 elements I do not understand why it happened

It my code for parsing JSON :

   let timeStamp = NSNumber(value: Date().timeIntervalSinceNow)

    var programs = [PrograToDayModel]()

    override func viewDidLoad() {
        super.viewDidLoad()

        super.viewDidLoad()
        let timeStamp = NSNumber(value: Date().timeIntervalSinceNow)
        self.downloadPrograms(for: timeStamp)

    }

    func downloadPrograms(for timestamp: NSNumber) {

        Alamofire.request("http://52.50.138.211:8080/ChanelAPI/programs/\(timestamp)").responseArray { (response: DataResponse<[PrograToDayModel]>) in

            let programlArray = response.result.value

            if let programlArray = programlArray {
                for program in programlArray {

                    self.programs.append(program)
                    print(program.title as Any)
                }


            }
            DispatchQueue.main.async {
                self.tableView.reloadData()
            }
        }
    }

it good i print element in console : enter image description here

my code for table:

    // MARK: - Table view data source

    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
         print(self.programs.count as Any)
        return self.programs.count

    }


    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "ProgramTableViewCell", for: indexPath) as! ProgramTableViewCell

        cell.title.text = self.programs[indexPath.row].title

        return cell
    }
}

All identifiers in place I using tab bar, tableView, tableViewCell How can I solve this problem?

Umair Afzal
  • 4,947
  • 5
  • 25
  • 50
  • 3
    There must be a reason mention in the debugger. Please share that as well. – Umair Afzal Feb 02 '17 at 11:23
  • 2
    There should be more information in the debugger about that NSException. It should help. – Larme Feb 02 '17 at 11:23
  • 1
    @Umair Afzal thats all : warning: could not load any Objective-C class information. This will significantly reduce the quality of type information available. and my print and libc++abi.dylib: terminating with uncaught exception of type NSException –  Feb 02 '17 at 11:26
  • 1
    @ Larme thats all : warning: could not load any Objective-C class information. This will significantly reduce the quality of type information available. and my print and libc++abi.dylib: terminating with uncaught exception of type NSException –  Feb 02 '17 at 11:27
  • 1
    Please make a breakpoint in `tableView(_: cellForRowAt indexPath:)` and check the return value of `dequeueReusableCell`. See if cell is not nil and if cell.text is initialized as well. – kiecodes Feb 02 '17 at 11:35
  • @Kie tableView(_: cellForRowAt indexPath:) this method is not called –  Feb 02 '17 at 11:41
  • 1
    Can you try to set a breakpoint for the exceptions. Maybe we can get more information this way: http://stackoverflow.com/a/17802723/389007 – kiecodes Feb 02 '17 at 11:43
  • @Kie AppDelegate signal SIGABRT and console libc++abi.dylib: terminating with uncaught exception of type NSException (lldb) I dont found error –  Feb 02 '17 at 11:57
  • 1
    Too little exception info there. Have you set "OS_ACTIVITY_MODE" environment variable to 'disable'? – Daniyar Feb 02 '17 at 12:00
  • @Astoriaso I did it –  Feb 02 '17 at 12:14
  • In cellForRowAt method - Look at second line code. Create the iboutlet with different name [dont take as title]. Try it. or change ProgramTableViewCell to UItableViewCell. – Pavankumar Feb 02 '17 at 12:46
  • 1
    Did you set the datasource and delegate for your tableView? – koen Feb 02 '17 at 16:29
  • @Koen so I did it –  Feb 02 '17 at 17:18
  • @Pavankumar I not go to this method –  Feb 02 '17 at 17:19
  • 1
    Which version of Swift are you using? – koen Feb 02 '17 at 17:23
  • @koen Swift 3.0 –  Feb 02 '17 at 17:23
  • 1
    @koen I found error : error in __connection_block_invoke_2: Connection interrupted –  Feb 02 '17 at 17:30
  • Maybe this can help: http://stackoverflow.com/questions/42000855/tableview-nsexception/ – koen Feb 02 '17 at 17:36
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/134702/discussion-between---and-koen). –  Feb 02 '17 at 17:52
  • @Koen it my question –  Feb 02 '17 at 17:53

2 Answers2

3

To identify the issue, you can just try this -

it might be a reason for that issue

So go to Main.storyboard, and right-click on View Controller at the top of the phone outline and remove any outlets with yellow flags (if any).

enter image description here

Prema Janoti
  • 836
  • 5
  • 18
0

I was getting a similar non descriptive error when trying to initialize a uitableviewcontroller when trying to add a section/number of rows. Did you register a tableview cell class? I see that you have a custom tableview cell created, so if that isn't registered with your tableview that might be causing this error.

   tableView.register("ProgramTableViewCell".self, forCellReuseIdentifier: "ProgramTableViewCell")
Josh
  • 7
  • 4