Recently (I think when updated to Xcode 14.3) my macOS Shortcut actions (implemented via AppIntent) started having a problem:
- When I click an action's AppEntity parameter I see the following error instead of seeing a list of entries to select from.
The action “Demo Action” could not run because an internal error occurred.
One difference that I notice between my builds that didn't exhibit this error and my builds that do exhibit the error:
- Working builds include
objects.appintentsmanifest
in the metadata folder - Builds that break with the above behavior do not include that file
Did something change in recent Xcode? What do I need to do so that Shortcuts app will run my queries again and provide popups so that I can select queried AppEnties?
To recreate the problem I created a new Document Based App in Xcode 14.3 and included the following code. I then dragged "Demo Action" into a new Shortcut and clicked "Show More" and then clicked "Books: Choose".
import AppIntents
struct BookEntity: Identifiable, AppEntity {
var id: UUID
@Property(title: "Title")
var title: String
var displayRepresentation: DisplayRepresentation {
DisplayRepresentation(title: LocalizedStringResource(stringLiteral: title))
}
init(id: UUID, title: String?) {
self.id = id
self.title = title ?? "Unknown Title"
}
static var typeDisplayRepresentation: TypeDisplayRepresentation = "Book"
static var defaultQuery = BookQuery()
}
struct BookQuery: EntityStringQuery {
func entities(for identifiers: [UUID]) async throws -> [BookEntity] {
library.filter { identifiers.contains($0.id) }
}
func entities(matching query: String) async throws -> [BookEntity] {
library.filter { $0.title.localizedCaseInsensitiveContains(query) }
}
func suggestedEntities() async throws -> [BookEntity] {
library
}
}
struct DemoAction: AppIntent {
static var title: LocalizedStringResource = "Demo Action"
@Parameter(title: "Books")
var books: [BookEntity]
func perform() async throws -> some IntentResult {
.result()
}
}
let library: [BookEntity] = [
BookEntity(id: UUID(), title: "The Hobbit"),
BookEntity(id: UUID(), title: "The Lord of the Rings"),
]