Hello, I'm attempting to learn the basics of AppIntents.
My test Hello World intent takes a number and doubles it.
This page (https://developer.apple.com/documentation/appintents/providing-your-app-s-capabilities-to-system-services) seems to imply that you can return types from the perform() function.
My code compiles, but crashes at runtime with the error
perform() returned types not declared in method signature - Did not declare ReturnsValue but provided one
Code:
struct DoubleANumber: AppIntent {
static var title: LocalizedStringResource = "Double a number"
static var description =
IntentDescription("Given a number, gives back twice that number.")
@Parameter(title: "Start Number")
var inputNumber: Double
static var parameterSummary: some ParameterSummary {
Summary("The number to double")
}
func perform() async throws -> some IntentResult & ReturnsValue {
let outputNumber = inputNumber * 2
return .result(value: outputNumber)
}
}
The value returned in the value
property of the IntentResult
is a Double. I would have assumed that this would be a valid primitive type (as mentioned in the earlier section of that docs page, covering parameters) and that the actual type returned is the wrapper .result
type would be covered in the type in the method signature some IntentResult & ReturnsValue
What am I missing? Thanks.
Ahh, I see. ReturnsValue
is generic and you have to provide the concrete type you are going to return.
https://developer.apple.com/forums/thread/723455
So in my case, the perform
method signature needs to be func perform() async throws -> some IntentResult & ReturnsValue<Double>
The docs could be a bit clearer here IMHO.