ios - Cannot invoke "save" with an argument list of type "(nil)' -


need blow code. updated xcode 7 beta

i following error "cannot invoke "save" argument list of type "(nil)'". working in ios 6

import uikit import coredata  class itemviewcontroller: uiviewcontroller { @iboutlet weak var textfielddivenumber: uitextfield! @iboutlet weak var textfielddivedate: uitextfield! @iboutlet weak var textfielddivelocation: uitextfield!   override func viewdidload() {     super.viewdidload()      // additional setup after loading view. } @ibaction func savetapped(sender: anyobject) {      let appdel: appdelegate = uiapplication.sharedapplication().delegate as! appdelegate      let contxt: nsmanagedobjectcontext = appdel.managedobjectcontext     let en = nsentitydescription.entityforname("list", inmanagedobjectcontext: contxt)      var newitem = model(entity: (en)!, insertintomanagedobjectcontext: contxt)      newitem.divenumber = textfielddivenumber.text!     newitem.divedate = textfielddivedate.text!     newitem.divelocation = textfielddivelocation.text!      contxt.save(nil)        self.navigationcontroller?.poptorootviewcontrolleranimated(true) }   override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated. }    } 

this has been asked several times since last monday, finding & marking duplicates se ios app cumbersome, so...

in swift 2, nsmanagedobjectcontext's save() method marked throws, have handle error comes it. (and don't pass error pointer parameter.)

your swift 1 code ignoring errors; swift 2 equivalent empty catch:

do {     try context.save() } catch {     // can go business. move along.  } 

ignoring errors isn't great idea, though. if don't want make error user-recoverable doing useful in catch, plan crash on error:

try! context.save() 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -