xcode - thread 1 exc_bad_instruction.. Error with swift -
i'm in need of serious help. i'm trying create database in xcode project of firebase, keep getting same exact error after build succeeds , closes giving me error :
thread 1 exc_bad_instruction (code=exc_i386_invop subcode=0x0)
any idea about?
here's line of code error on.
let label2 = cell.viewwithtag(2)as! uilabel
here's of code
// // database.swift // intern // // created lani daniels on 8/20/17. // copyright © 2017 lani daniels. rights reserved. // import uikit import firebase import firebasedatabase struct poststruct { let title: string let message: string } class databaseviewcontroller: uitableviewcontroller { var posts: [poststruct] = [] override func viewdidload() { super.viewdidload() // let databaseref = database.database().reference() databaseref.child("posts").queryorderedbykey().observe(.childadded, with: { snapshot in let snapshotvalue = snapshot.value as? nsdictionary let title = snapshotvalue?["title"] as? string let message = snapshotvalue?["message"] as? string self.posts.insert(poststruct(title: title ?? "", message: message ?? ""), at: 0) self.tableview.reloaddata() }) post() } func post(){ let title = "title" let message = "message" let post : [string : anyobject] = ["title" : title anyobject, "message" : message anyobject] let databaseref = database.database().reference() databaseref.child("posts").childbyautoid().setvalue(post) } override func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int { return posts.count } override func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell { let cell = tableview.dequeuereusablecell(withidentifier: "cell", for: indexpath) let label1 = cell.viewwithtag(1)as! uilabel label1.text=posts[indexpath.row].title let label2 = cell.viewwithtag(2)as! uilabel // error code: thread 1 exc_bad_instruction (code=exc_i386_invop subcode=0x0) label2.text=posts[indexpath.row].message return cell } }
thread 1 exc_bad_instruction (code=exc_i386_invop subcode=0x0) error means app determined elements should exists, crash when doesn't
in case, there might 2 reasons why happening:
- please check whether view tagged "2" uilabel.
- please check whether view tagged "2" exist.
the reason of crashing should either 1 of them.
Comments
Post a Comment