With iOS/Apple AppIntents, your iOS app can declare AppIntents, which customers can use from the Shortcuts App to make use of as steps in their very own manually/Siri/and so forth triggered Shortcuts, but in addition from their very own Automations (when a sure occasion happens, run a sequence of AppIntents or a selected Shortcut and so forth), to run code you’ve got outlined.
If you wish to dynamically set off observe up AppIntents, your Person has to make use of the if logic to wrap the AppIntent as they use it to make a Shortcut.
As a substitute, is it attainable to dynamically chain/set off totally different AppIntents, utilizing OpensIntent?
I attempted it. However I get this compiler error. I am new to Swifts kind system, and I can’t determine whether or not it is attainable to by some means wrap NextAppIntent and OtherNextAppIntent in an enum or protocol or another language function to resolve this.
ERROR: Perform declares an opaque return kind 'some IntentResult & ReturnsValue<String> & OpensIntent', however the
return statements in its physique do not need matching underlying sorts
Error prompted resulting from NextAppIntent, OtherNextAppIntent have totally different kind
Is it attainable to resolve this compiler error and subsequently obtain dynamically chaining totally different AppIntents with OpensIntent? (I might guess that this compiler error will not be solvable and represents it’s not supposed to have the ability to dynamically chain totally different AppIntents with OpensIntent)
E.g.
First Intent
@obtainable(iOS 16.0, *)
struct SomeAppIntent: AppIntent {
// Arbitrary parameter
@Parameter(title: "App")
var app: String
@MainActor
func carry out(
) async throws -> some IntentResult & ReturnsValue<String> & OpensIntent {
// use api to determine some situation
var some_condition: Bool = some_api.check_some_thing()
if (some_condition) {
return .end result(
worth: app,
opensIntent: NextAppIntent(app: $app)
)
} else {
return .end result(
worth: app,
opensIntent: OtherNextAppIntent(app: $app)
)
}
}
}
// diff file
@obtainable(iOS 16.0, *)
struct NextAppIntent: AppIntent {
// Arbitrary parameter
@Parameter(title: "App")
var app: String
static var openAppWhenRun: Bool = true
@MainActor
func carry out(
) async throws -> some IntentResult {
...
}
}
// diff file
@obtainable(iOS 16.0, *)
struct OtherNextAppIntent: AppIntent {
// Arbitrary parameter
@Parameter(title: "App")
var app: String
static var openAppWhenRun: Bool = false
@MainActor
func carry out(
) async throws -> some IntentResult {
...
}
}
Q: Why not simply dynamically invoke the performance all within the first app intent?
A: Typically you may want the performance to be separated into separate app intents i.e. static var openAppWhenRun: Bool = false|true
Q: What about simply utilizing throw error or exit(0) to forestall development to subsequent app intent?
A: It’s a hacky workaround, however the consumer will all the time be notified that an error occurred AFAICS. You additionally won’t have the ability to specific the conditional logic you need.