1
我试图从本地通知被触发时从代码数据模型中删除数据。所以,我得到通知的alertbody
,然后利用获取通知的标题数据进行排序:使用UILocalNotification从核心数据中删除数据
func application(application: UIApplication, handleActionWithIdentifier identifier: String?,
forLocalNotification notification: UILocalNotification, completionHandler:() -> Void) {
if identifier == "deleteEvent" {
context = CoreDataStack.managedObjectContext
do {
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")
}
do {
results.removeAtIndex(0)
CoreDataStack.saveContext()
NSNotificationCenter.defaultCenter().postNotificationName("reloadTableView", object: nil)
print(results.count) // returns 0
}
}
completionHandler()
}
,当我从模型中取出数据,并转到例如事件视图控制器我依然可以看到数据有!我错过了什么吗?!谢谢。
@santa你会检查吗? –