Siri Shortcuts with CoreData

Hello

I created a simple SwiftUI app with Core Data and I want to be able to add data via the shortcuts app, I created a shortcut that takes some text as input and returns it in uppercase and when I run the shortcut in the shortcuts app, it works, however when I added an "add" function (to save data in the Core Data database) to the intent handle function, and I run it again nothing is saved in the app, here is the code:

class MakeUppercaseIntentHandler: NSObject, MakeUppercaseIntentHandling {
    let persistenceController = PersistenceController()
    func handle(intent: MakeUppercaseIntent, completion: @escaping (MakeUppercaseIntentResponse) -> Void) {
        if let inputText = intent.text {
            let uppercaseText = inputText.uppercased()
                    
            completion(MakeUppercaseIntentResponse.success(result: add(text: uppercaseText)))
            
        } else {
            completion(MakeUppercaseIntentResponse.failure(error: "The text entred is invalid"))
        }
    }
    
    func resolveText(for intent: MakeUppercaseIntent, with completion: @escaping (MakeUppercaseTextResolutionResult) -> Void) {
        if let text = intent.text, !text.isEmpty {
            completion(MakeUppercaseTextResolutionResult.success(with: text))
        } else {
            completion(MakeUppercaseTextResolutionResult.unsupported(forReason: .noText))
        }
    }
    
    func add(text: String) -> String{
        let newItem = Item(context: persistenceController.container.viewContext)
        newItem.text = text
        
        do {
            try persistenceController.container.viewContext.save()
        } catch {
            let nsError = error as NSError
            fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
        }
        
        return text
    }
}

Thank You

I just solved it, I forgot to add App Groups, however the app isn't refreshing, to see the new data I have to close it and reopen it, any clue on how to fix this issue, I will post my CoreData Stack

mistake

import CoreData

struct PersistenceController {
    static let shared = PersistenceController()

    let container: NSPersistentContainer

    init() {
        container = NSPersistentContainer(name: "SiriShort")

        guard let fileContainer = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.SiriShortcut2")?.appendingPathComponent("SiriShort.sqlite") else {
            fatalError("Shared file container could not be created.")
        }
        
        let storeDescription = NSPersistentStoreDescription(url: fileContainer)
        storeDescription.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey)
        storeDescription.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)
        
        container.persistentStoreDescriptions = [storeDescription]
        
        container.loadPersistentStores(completionHandler: { (storeDescription, error) in
            if let error = error as NSError? {
                fatalError("Unresolved error \(error), \(error.userInfo)")
            }
        })
        
        container.viewContext.automaticallyMergesChangesFromParent = true
        container.viewContext.mergePolicy = NSMergeByPropertyStoreTrumpMergePolicy
    }
}
Siri Shortcuts with CoreData
 
 
Q