I've got a simple app delegate method to create a core data object when my push notification arrives. The save() is returning nilError and I can't figure out what I'm doing wrong.
I've verified all the elements of Message have expected data. The attributes are just String, Data, and Date types.
I've verified all the elements of Message have expected data. The attributes are just String, Data, and Date types.
Code Block swift class AppDelegate: NSObject, UIApplicationDelegate { @Environment(\.managedObjectContext) private var managedObjectContext func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { guard let text = userInfo["text"] as? String, let image = userInfo["image"] as? String, let url = URL(string: image) else { completionHandler(.noData) return } let context = self.managedObjectContext URLSession.shared.dataTask(with: url) { data, response, error in guard let data = data, error == nil else { completionHandler(.failed) return } context.perform { let message = Message(context: context) message.text = text message.image = data message.received = Date() do { try context.save() completionHandler(.newData) } catch { print(error) completionHandler(.failed) } } }.resume() }