swift3 - TableView crashes under uncaught exception 'NSUnknownKeyException', this class is not key value coding-compliant for the key x.' -


i can't seem make tableview custom cells work. runtime error

terminating app due uncaught exception 'nsunknownkeyexception', reason: '[ setvalue:forundefinedkey:]: class not key value coding-compliant key causecampaigndescription.'

the weird thing that property not called anymore. cell file mainviewcontrollertableviewcell

// //  mainviewcontrollertableviewcell.swift //  // //  created on 9/13/17. //  copyright © 201. rights reserved. //  import uikit  class mainviewcontrollertableviewcell: uitableviewcell {       @iboutlet weak var causecampaignimageview: uiimageview!        @iboutlet weak var causedescription: uilabel!       @iboutlet weak var daystofinishlabel: uilabel!       @iboutlet weak var raisedovertotallabel: uilabel!       @iboutlet weak var percentagecompletedlabel: uilabel!      @iboutlet weak var goalprogresview: uiprogressview!       //card used on     @ibinspectable var cornerradius : cgfloat = 2      @ibinspectable var shadowoffsetwidth : cgfloat = 0      @ibinspectable var shadowoffsetheight : cgfloat = 5      @ibinspectable var shadowcolor : uicolor = uicolor.black      @ibinspectable var shadowopacity : cgfloat = 0.5        override func awakefromnib() {         super.awakefromnib()         // initialization code     }      override func setselected(_ selected: bool, animated: bool) {         super.setselected(selected, animated: animated)          // configure view selected state     }      override func layoutsubviews() {         layer.cornerradius = cornerradius         layer.shadowcolor = shadowcolor.cgcolor         layer.shadowoffset = cgsize(width: shadowoffsetwidth, height: shadowoffsetheight)         let shadowpath = uibezierpath(roundedrect: bounds, cornerradius: cornerradius)         layer.shadowpath = shadowpath.cgpath         layer.shadowopacity = float(shadowopacity)     }   } 

and view controller holds table view mainviewcontroller:

// //  viewcontroller.swift //  // //  created on 1/28/17. //  copyright © 2017. rights reserved. //  import uikit import alamofire import swiftyjson import firebase   class mainviewcontroller: uiviewcontroller,uitableviewdelegate,uitableviewdatasource {      var campaignrowsdata  = [causecampaign]()      var serverfetchcampaignsurl = config.global._serverurl        @iboutlet weak var campaigntableview: uitableview!       //show navigation controller bar      var facebookid = "", twitterid = "",firebaseid = ""       override func viewdidload() {         super.viewdidload()         // additional setup after loading view, typically nib.          //hide bar navigation controller          settoolbar()          campaigntableview.delegate=self          campaigntableview.datasource=self          campaigntableview.separatorcolor = uicolor(white: 0.95, alpha: 1)          recoveruserdefaults()          getcampaignlist()            //print(facebookid, twitterid, firebaseid)      }       func settoolbar(){         //hide bar navigation controller         self.navigationcontroller?.isnavigationbarhidden = false          self.navigationitem.sethidesbackbutton(true, animated: false)          self.navigationcontroller?.navigationbar.bartintcolor = uicolor.purple        }      func getcampaignlist(){          alamofire.request(serverfetchcampaignsurl+"/campaigns/get/all/user/\(twitterid)/firebase/\(firebaseid)/cat/0", method: .get).validate().responsejson { response in             switch response.result {             case .success(let data):                   let campaigncausesjson = json(campaigncausesdata: data)                  self.parsecampaigncauseslistresponse(campaigncausesjson)                  //alternative thread operation                   dispatchqueue.main.async {                     self.campaigntableview.reloaddata()                  }              case .failure(let error):                 print(error)             }         }      }      func parsecampaigncauseslistresponse(_ campaigncausesjson:json){          if let activecampaigncount = campaigncausesjson["active_campaigns_count"].string {             //now got value             print("total_active_campaigns",activecampaigncount)             campaignsglobaldatamanagerutil.campaigntotalcount = int(activecampaigncount)!         }          if let contributoruserid = campaigncausesjson["contributor_user_id"].string {             //now got value             print("contributor_user_id",contributoruserid)             currentuserutil.contributoruserid = contributoruserid         }          if let usertwitterfollowersqty = campaigncausesjson["user_twitter_followers_qty"].int {             //now got value             print("user_twitter_followers_qty",usertwitterfollowersqty)             currentuserutil.twitterfollowerscount = int(usertwitterfollowersqty)         }          //parsing campaigns object array            campaigncausesjson["camp_array"].arrayvalue.map({              let campaigncause:json = $0               parsecampaign(campaigncause)           })         }     //todo:change datatape object     func parsecampaign(_ causecampaign:json){          let causecampaignobject: causecampaign = causecampaign();          causecampaignobject.description = causecampaign["cause_description"].stringvalue           causecampaignobject.id = causecampaign["campaign_id"].stringvalue           if let contributorsqty = causecampaign["contributors_qty"].int{             causecampaignobject.contributorsqty = contributorsqty          }          causecampaignobject.currencysymbol = causecampaign["currency_symbol"].stringvalue          if let currentcontributions = causecampaign["current_contributions"].float{             causecampaignobject.currentcontributions = currentcontributions          }          if let goal = causecampaign["goal"].float {             causecampaignobject.goal = goal         }          if let goalpercentageachieved = causecampaign["goal_percentage_achieved"].float{             causecampaignobject.goalpercentageachieved = causecampaign["goal_percentage_achieved"].float!         }          causecampaignobject.hashtag = causecampaign["hashtag"].stringvalue          causecampaignobject.name = causecampaign["name"].stringvalue          if let remainingammounttogoal = causecampaign["remaining_ammount_to_goal"].float{             causecampaignobject.remainingammounttogoal = remainingammounttogoal         }          if let picurl =  causecampaign["pic_url"].stringvalue as? string {             causecampaignobject.picurl = picurl         }          if let campaignstartingdate = causecampaign["created_at"].string{             causecampaignobject.campaignstartingdate = campaignstartingdate         }          if let campaignendingdate = causecampaign["campaign_ending_date"].string{             causecampaignobject.campaignendingdate = campaignendingdate          }           var foundationsarray = [foundation]()          causecampaign["foundations"].arrayvalue.map({              let id = $0["foundation_id"].stringvalue             let twitterusername = $0["twitter_username"].stringvalue             let picpath = $0["pic_path"].stringvalue             let name = $0["name"].stringvalue              let foundation:foundation = foundation(id,twitteraccount: twitterusername,picpath: picpath,name: name)              foundationsarray.append(foundation)         })           causecampaignobject.foundations = foundationsarray           campaignrowsdata.append(causecampaignobject)  //        foundations = "<null>";  //innecesario //        sacar de la request inicial??? //        "went_inactive_date" = "<null>"; //        "tweet_id" = 900936910494810112;       }         func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int {         return campaignrowsdata.count      }      func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell {         let cell = campaigntableview.dequeuereusablecell(withidentifier: "campaigncell", for: indexpath) as! mainviewcontrollertableviewcell      //setting card attributes         print("row",campaignrowsdata[indexpath.row].description)         let campaigncause:causecampaign = campaignrowsdata[indexpath.row]          if let desc = campaigncause.description as? string{                 cell.causedescription.text = desc         } else {             print("null")         }          return cell     }       func recoveruserdefaults(){         if let fbid = userdefaults.standard.object(forkey: config.global._facebookiduserdefaults) as? string {             facebookid = fbid         }else{             print("facebook id null")         }            if let twtid = userdefaults.standard.object(forkey: config.global._twitteriduserdefaults) as? string{             twitterid = twtid         }else{             print("twitter id null")         }           if  let firid = userdefaults.standard.object(forkey: config.global._firebaseiduserdefaults) as? string{             firebaseid = firid         }else{             print("twitter id null")         }          return     }    } 
  1. the app crashes if line reloaddata uncommented (i don't know when , if should use this)
  2. if set label can't see on screen, see blank cards, again, uncomment reloaddata crashes
  3. there's no causecampaigndescription, it's called causedescription don't know why error keeps mentioning field
  4. the data desc ok since printed , has right content it's not that

what problem?

searching project causecampaigndescription turn offending xib and/or storyboard containing outdated key path. however, it's been experience xcode not 100% reliable finding things in xibs , storyboards, if xcode's search feature won't find it, command in terminal turn straightaway:

find /path/to/your/project/directory -name .git -prune -or -type f -exec grep causecampaigndescription {} \; -print 

once find offending item in xib or storyboard, change correct string , should solve problem.


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -