ios - Coredata in swift -
hello having issue core data in swift, doesn't show error doesn't print when believe should returning 'joe' + 'pass' in console. please?
import uikit import coredata class viewcontroller: uiviewcontroller { override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. var appdel:appdelegate = uiapplication.sharedapplication().delegate as! appdelegate var context:nsmanagedobjectcontext = appdel.managedobjectcontext var newuser = nsentitydescription.insertnewobjectforentityforname("users", inmanagedobjectcontext: context) nsmanagedobject newuser.setvalue("joe", forkey: "username") newuser.setvalue("pass", forkey: "password") { try context.save() } catch let error { print("couldn't save user data") print(error) } let request = nsfetchrequest(entityname: "users") request.returnsobjectsasfaults = false { var results = try context.executefetchrequest(request) results = results as! [nsmanagedobject] if results.count > 0 { results in results { print(results) }} } catch let error nserror { print(error) } } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } }
you should create own coredata class (as subclass of nsmanagedobject) , create array out of class.
specify want print. in case
newuser.username
Comments
Post a Comment