ios - TableView definition conflict with previous using CoreData in Mutable array -
i trying access coredata , putting tableview have data mutable array when try access tableview got error.
my code follows:
import uikit import coredata class tableview: uiviewcontroller, uitableviewdelegate { @iboutlet weak var tableview: uitableview! override func viewdidload() { var desc_arr: [string] = [] var amt_arr: [string] = [] let appdel: appdelegate = uiapplication.sharedapplication().delegate as! appdelegate let context: nsmanagedobjectcontext = appdel.managedobjectcontext let request = nsfetchrequest(entityname: "expense") request.returnsobjectsasfaults = false { let results = try context.executefetchrequest(request) if results.count > 0 { result in results as! [nsmanagedobject] { if let desc = result.valueforkey("desc") as? string { print(desc) desc_arr.append(desc) } if let amt = result.valueforkey("amt") as? string{ print(amt) amt_arr.append(amt) } } } } catch { print("fetch failed") } print(desc_arr) print(amt_arr) func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { return desc_arr.count } override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let cell = uitableviewcell(style: uitableviewcellstyle.default, reuseidentifier: "cell") cell.textlabel?.text = desc_arr[indexpath.row] return cell } } }
Comments
Post a Comment