swift - Core Data can not be saved using UIapplication as a delegate -


i trying use core data save data. created entity called newproject in xmodel. however, when try save data clicking start button. doesn't work, don't know wrong.

 func saveasinglenewproject(eventtitle: string, starttime : string) {     let appdelegate = uiapplication.sharedapplication().delegate as! appdelegate      let managedcontext = appdelegate.managedobjectcontext      let entity = nsentitydescription.entityforname("newproject", inmanagedobjectcontext: managedcontext)      let anewproject = nsmanagedobject(entity: entity!, insertintomanagedobjectcontext: managedcontext)      anewproject.setvalue(eventtitle, forkey: "eventtitle")     anewproject.setvalue(starttime, forkey: "starttime")       {         try managedcontext.save()         //projectlist.append(anewproject)         print ("reached part")     }catch let error nserror {         print ("could not save it")     }   }     @ibaction func startbutton(sender: anyobject) {     if firsttimeclick == 0 {  timer = nstimer.scheduledtimerwithtimeinterval(1, target: self, selector: ("updatecounter"), userinfo: nil, repeats: true)     firsttimeclick = 1     }      // assign project title variable     if currentprojecttitle != nil {     projecttitle = currentprojecttitle.text!     }       //create single project       //when start pressed, window closes     currentprojecttitle.text = nil     currentprojectdisplay.text = projecttitle!      //save values        saveasinglenewproject("anew project", starttime: "30 minutes interval")   } 


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -