AppIntents

Overview

  • I have a custom type Statistics that has 3 properties inside it
  • I am trying to return this as part of the AppIntent's perforrm method
struct Statistics {
    var countA: Int
    var countB: Int
    var countC: Int
}

I would like to implement the AppIntent to return Statistics as follows:

func perform() async throws -> some IntentResult & ReturnsValue<Statistics> {
...
...
}

Problem

  • It doesn't make much sense to make Statistics as an AppEntity as this is only computed as a result.
  • Statistics doesn't exist as a persisted entity in the app.

Questions

  1. How can I implement Statistics?
  2. Does it have to be AppEntity (I am trying to avoid this)? (defaultQuery would never be used.)
  3. What is the correct way tackle this?
Answered by DTS Engineer in 871075022

It doesn't make much sense to make Statistics as an AppEntity as this is only computed as a result.

You're spot on with that thought, which is why there's TransientAppEntity. There's even an example of generated statistics to show this API off in a sample code project — take a look at the ActivityStatisticsSummary structure in that project!

— Ed Ford,  DTS Engineer

Accepted Answer

It doesn't make much sense to make Statistics as an AppEntity as this is only computed as a result.

You're spot on with that thought, which is why there's TransientAppEntity. There's even an example of generated statistics to show this API off in a sample code project — take a look at the ActivityStatisticsSummary structure in that project!

— Ed Ford,  DTS Engineer

@DTS Engineer Thanks a lot Ed! that was spot on, exactly what I wanted.

I was breaking my head over this!

AppIntents
 
 
Q