reports
reports copied to clipboard
FB12196730: AppIntents should allow using if-statements in ParameterSummary
- Date: 2023-05-21
- Resolution: Open
- Area: AppIntents
- OS: macOS 13.4
- Type: Suggestion
Description
When you need a parameter to only be visible if another parameter is true, you would currently have to do this:
static var parameterSummary: some ParameterSummary {
When(\.$shouldLimit, .equalTo, true) {
Summary("Shuffle \(\.$list)") {
\.$shouldLimit
\.$limit
}
} otherwise: {
Summary("Shuffle \(\.$list)") {
\.$shouldLimit
}
}
}
However, it becomes a boilerplate mess if you need more than one conditional parameter.
It would be much nicer if we could use normal if-statements like this:
static var parameterSummary: some ParameterSummary {
Summary("Shuffle \(\.$list)") {
\.$shouldLimit
if shouldLimit {
\.$limit
}
}
}
Here is a real-world example of how much duplication it causes: https://github.com/sindresorhus/Actions/blob/5323d86e210fd12d163ea18702eab513abc5daba/Shared/Actions/ChooseFromListExtended.swift#L57-L97 And with so much duplication, it's very easy to miss a parameter.
static var parameterSummary: some ParameterSummary {
When(\.$selectMultiple, .equalTo, true) {
When(\.$useTimeout, .equalTo, true) {
Summary("Choose from \(\.$list)") {
\.$prompt
\.$selectMultiple
\.$selectAllInitially
\.$useTimeout
\.$timeout
\.$timeoutReturnValue
\.$allowCustomItems
}
} otherwise: {
Summary("Choose from \(\.$list)") {
\.$prompt
\.$selectMultiple
\.$selectAllInitially
\.$useTimeout
\.$allowCustomItems
}
}
} otherwise: {
When(\.$useTimeout, .equalTo, true) {
Summary("Choose from \(\.$list)") {
\.$prompt
\.$selectMultiple
\.$useTimeout
\.$timeout
\.$timeoutReturnValue
\.$allowCustomItems
}
} otherwise: {
Summary("Choose from \(\.$list)") {
\.$prompt
\.$selectMultiple
\.$useTimeout
\.$allowCustomItems
}
}
}
}
There is a severely under-documented Switch/Case available which might solve this issue.
https://developer.apple.com/documentation/appintents/appintent/switch
example use:
Switch(\.$match) {
Case(.specific) {
Summary {
\.$match
\.$specificMatch
\.$theme
}
}
Case(.latestOpponent) {
Summary {
\.$match
\.$opponent
\.$theme
}
}
DefaultCase {
Summary {
\.$match
\.$theme
}
}
}
@gregggreg I'm well aware of Switch/Case. Like When, it doesn't solve the nesting problem described in the feedback report.