ローカル通知が発生したときにコードデータモデルからデータを削除しようとしています。だから私は、通知のタイトルを使用して、ソートデータをフェッチ、通知の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これをチェックしますか? –