AppIntent Entity not passed in Shortcut

Creating my first IOS appIntents.

I created two simple appIntents. One to create a random number and the other to store it (actually it just prints it).

Yet, when I run a shortcut that connects the two, the one that stores it is not receiving the entity.

It receives nil instead of the entity created in the first step.

The first thing I noticed is that you're using a UUID for RandomNumberEntity. That in itself is not a problem, except that the UUID is always changing because you create it using UUID() in your implementation. An entity needs to have a stable identifier so that the same entity from your app is always represented by the same UUID value.

The second thing is that I don't see an EntityQuery here. You need to implement an EntityQuery, and it needs to implement the entities(for:) method at a minimum. Borrowing an example from the documentation , that might look like this:

struct MyPhotoQuery: any EntityQuery {
    func entities(for identifiers: [UUID]) async throws -> [MyPhoto] {
        myPhotoStore.filter { ids.contains($0.id) }
    }

Notice that the type of the identifiers parameter is a UUID, which is convenient to match your test project. The system will call that method with an identifiable value (such as your UUID), and your query needs to return the entity for that value. This connects to my first point about using a stable identifier — the identifiers that you create for your random numbers then must return that random number entity if the system asks you for that entity again by its identifier.

This might make a bit more sense if you implement your test project using Int as your Identifiable value rather than UUID, since your test project is generating random numbers. The id property can be the same random number integer as the value that you boxed into the RandomNumberEntity type, and then the query would be asking you for an entity matching an integer, which means its easy for you to always return the same integer with the same stable id.

— Ed Ford,  DTS Engineer

does that mean an app entity can only be used between shortcuts used by the same app?

In other words, I cannot use an app entity outside the app in which it originates?

An AppEntity that also conforms to Transferable opens up a world of integrations for common data types that many apps understand. Our Trails sample app has an example you can look at where the workout summary can be rendered into an image, rather than just as String data, just as one example. (See the comments in ActivityStatisticsSummary+Transferable.swift for how to use it in the Shortcuts app to see the results.) My colleague explains more in a WWDC session.

—Ed Ford,  DTS Engineer

AppIntent Entity not passed in Shortcut
 
 
Q