ios - How to append NSString into NSmangedobject -
i new ios development. want know 1 thing appending string nsmenged object giving me error please resolve it
here code-
let json1 = try nsjsonserialization.jsonobjectwithdata(response.data!, options:.allowfragments) let json2 = json1["interests"] as! nsarray // print(json2) var i=0; i<json2.count; i++ { let object = json2[i] as! nsdictionary //print(object) let name = object["name"] as! nsstring print(name) self.names.append(name as! nsmanagedobject) }
in last line getting error.
try this:
let appdel:appdelegate = uiapplication.sharedapplication().delegate as! appdelegate let context:nsmanagedobjectcontext = appdel.managedobjectcontext let newcontact = nsentitydescription.insertnewobjectforentityforname("contact", inmanagedobjectcontext: context) newcontact.setvalue(txtname.text, forkey: "name") { try context.save() } catch { print("save error!") }
Comments
Post a Comment