I have make any improvements with this:
I'm getting my Core Data object id with
content.userInfo = ["objectId" : myObject.id!.uuidString]
Capturing back its value, after tapping on the notificacion, on AppDelegate with
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
//
if let objectId = userInfo["objectId"] as? String {
//(1)
//
And implementing a method on the view I want to be responsible of presenting data, using a FetchRequest with a predicate to match that id, and extracting it from de array
struct DetailView: View {
@Environment(\.managedObjectContext) var moc
@ObservedObject var object: Entity
//
public mutating func editFromId(id: String) {
//(2)
@FetchRequest(sortDescriptors: []) var objects: FetchedResults<Entity>
objects.nsPredicate = NSPredicate(format: "%K == %@", (\Entity.id) as! CVarArg, id)
object = objects.first ?? Entity()
}
//
But now, how could I "connect" object obtained on AppDelegate (1) for using it on the view (2)? How can I invoke editFromId funcion from AppDelegate?
I'm trying this, but unsucesfully, on AppDelegate
let detailView: DetailView?
detailView?.editFromId(id: objectId)
as it says "Constant 'detailView' passed by reference before being initialized".