ios - Remove data from core data using UILocalNotification -


i trying remove data code data model when local notification fired. notifications's alertbody ,then fetch sort data using notification title :

 func application(application: uiapplication, handleactionwithidentifier identifier: string?,                      forlocalnotification notification: uilocalnotification, completionhandler: () -> void) {           if identifier == "deleteevent" {              context = coredatastack.managedobjectcontext              {                  request =  nsfetchrequest(entityname: "event")                 let titlepredicate = nspredicate(format: "title contains[c] %@" ,notification.alertbody!)                  request.predicate = titlepredicate                 results = try context.executefetchrequest(request)                  print(results.count) // returns 1                } catch {                  print("error")             }                  {                      results.removeatindex(0)                     coredatastack.savecontext()                      nsnotificationcenter.defaultcenter().postnotificationname("reloadtableview", object: nil)                     print(results.count) // returns 0              }           }          completionhandler()     } 

when remove data model , go event view controller example still can see data there ! missing ?! thanks.

removing element results array (using removeatindex) not delete persistent store - or context. need tell context delete object:

let object = results[0] as! nsmanagedobject context.deleteobject(object) 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -