ios - crash in core data xcode 8 -
i facing issue in ios swift xcode 8
after setup core data , before insert junk data in purpose of testing fetch function app run correctly no crash , no data after insert data app crash below message
terminating app due uncaught exception 'nsunknownkeyexception', reason: '[<uitableviewcell 0x7f9b26054c00> setvalue:forundefinedkey:]: class not key value coding-compliant key deatials.
here code
// import uikit import coredata // nsfetchedresultscontrollerdelegate needed start woring in function datacore class mainvc: uiviewcontroller , uitableviewdelegate, uitableviewdatasource,nsfetchedresultscontrollerdelegate{ // definning main view table , segment. @iboutlet weak var tableview: uitableview! @iboutlet weak var segment: uisegmentedcontrol! // need difine nsfetchedresultscontroller define remaining 3 functions tableview var controller : nsfetchedresultscontroller<item>! override func viewdidload() { super.viewdidload() generatetesedata() attemptfetch() tableview.datasource = self tableview.delegate = self } // need define 3 main fucntions table view func numberofsections(in tableview: uitableview) -> int { if let sections = controller.sections{ return sections.count } return 0 } func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int { // need difine number of rows in section nsfetchedresultscontroller if let sections = controller.sections{ let sectioninfo = sections[section] return sectioninfo.numberofobjects } return 0 } func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell { // linking cell var class of itemcell been created in view folder let cell = tableview.dequeuereusablecell(withidentifier: "cellitem", for: indexpath) as! itemcell // function been created below: configurecell(cell: cell, indexpath: indexpath nsindexpath) return cell } func tableview(_ tableview: uitableview, heightforrowat indexpath: indexpath) -> cgfloat { return 150 } func configurecell (cell:itemcell, indexpath: nsindexpath){ let item = controller.object(at: indexpath indexpath) cell.configurecellsincellclass(item: item) } func attemptfetch () { let fetchrequest:nsfetchrequest<item> = item.fetchrequest() let datesort = nssortdescriptor(key: "created", ascending: false) fetchrequest.sortdescriptors = [datesort] let controller = nsfetchedresultscontroller(fetchrequest: fetchrequest, managedobjectcontext: context, sectionnamekeypath: nil, cachename: nil) self.controller = controller do{ try controller.performfetch() }catch{ let error = error nserror print("\(error)") } } // these 2 function update in tableview func controllerwillchangecontent(_ controller: nsfetchedresultscontroller<nsfetchrequestresult>) { tableview.beginupdates() } func controllerdidchangecontent(_ controller: nsfetchedresultscontroller<nsfetchrequestresult>) { tableview.endupdates() } //this function preforme functions <data core> func controller(_ controller: nsfetchedresultscontroller<nsfetchrequestresult>, didchange anobject: any, @ indexpath: indexpath?, type: nsfetchedresultschangetype, newindexpath: indexpath?) { switch(type) { case.insert: if let indexpath = newindexpath { tableview.insertrows(at: [indexpath], with: .fade) } break case.delete: if let indexpath = indexpath{ tableview.deleterows(at: [indexpath], with: .fade) } break case.update: if let indexpath = indexpath { let cell = tableview.cellforrow(at: indexpath) as! itemcell configurecell(cell: cell, indexpath: indexpath! nsindexpath) } break case.move: if let indexpath = indexpath { tableview.deleterows(at: [indexpath], with: .fade) } if let indexpath = indexpath { tableview.insertrows(at: [indexpath], with: .fade) } break } }
at point system cun without crash after add insert function in below it's start crashing
func generatetesedata(){ let item = item(context: context) item.title = "imac" item.price = 2000 item.details = "soon" }
this view cell file
class itemcell: uitableviewcell { // view take label view , link here @iboutlet weak var thump: uiimageview! @iboutlet weak var title: uilabel! @iboutlet weak var price: uilabel! @iboutlet weak var deatials: uilabel! // using function set values of items labels been linked before in upper section func configurecellsincellclass (item:item){ title.text = item.title price.text = ("$\(item.price)") deatials.text = item.details } }
thank guys in advance
Comments
Post a Comment