ios - Pass Properties or Managed Object ID Between Views - Core Data -
enter code here
using swift , xcode 6.
view one.swift = tableview.
view two.swift = view w/textfields (and other ui elements) alter according item chosen in tableview
i have coded pass managed object id chosen in tableview view 2 (as delegate property). but best approach?
//main view class var mainary = [string]() // tableview var objectsary = [nsmanagedobject]() var itemobchosen: nsmanagedobject? = nil //protocol property //loads table view , objectsary func loadmyitems() { objectsary.removeall() allow appdel: appdelegate = (uiapplication.sharedapplication().delegate appdelegate) allow contextob: nsmanagedobjectcontext = appdel.managedobjectcontext! allow cdfetch = nsfetchrequest(entityname: "items") var getdata = contextob.executefetchrequest(cdfetch, error: nil)! if(getdata.count > 0) { eachitem in getdata { var itemitem = eachitem.valueforkey("itemname") string! if (itemitem != nil) { objectsary.append(eachitem nsmanagedobject) } } } } //within didselectrowatindexpath itemclkdvar = indexpath.row itemobchosen = objectsary[itemclkdvar] //passed other view chosen object //fixed eliminate mainary maincell.textlabel?.text = self.objectsary[indexpath.row].valueforkey("itemname") as? string
ios core-data swift nsmanagedobject
No comments:
Post a Comment