iosswiftappintents

How to add a default value to an AppShortcut in @AppShortcutsBuilder in the new AppShortcutsProvider?


I tried a lot and was happy to see that this code first looks like the ideal setup:

 @AppShortcutsBuilder static var appShortcuts: [AppShortcut] {
        AppShortcut(intent: ExecuteAction(action: .init(title: "Start", default: .startTimer)), phrases: [
            "Start working time with \(.applicationName)",
        ])
    }

It builds YUHHU, but the action parameter is always nil in my class. Just to let you know, these shortcuts have been working pretty well for years now. Migrating them to the new AppIntents also worked well.

I just want to give the user the basic actions, but I have no idea why the default parameter is not working.


Solution

  • For everyone that come a cross here and have the same question, don't provide the defaults in the builder, instead on the parameter itself:

    @Parameter(title: "Action",default:.startTimer)
    var action: ActionAppEnum
    

    Works as expected.