I’m making a easy AppIntents Shortcut that requires UIKit to open a URL in my app. Although, as soon as I add the import UIKit
to my file, Xcode exhibits me the next warning on the caseDisplayRepresentations
, as a result of I take advantage of a picture for the show repreentations. With out importing UIKit (or with out the picture for the DisplayRepresentations) all the things works effective! Any concepts learn how to repair that?
Anticipated a direct name to the
Picture
initializer, obtainedSwift.Optionally available<AppIntents.DisplayRepresentation.Picture>
as a substitute
The Code
import AppIntents
import UIKit
enum AppView: Int, AppEnum {
case tab1
case tab2
static var typeDisplayRepresentation = TypeDisplayRepresentation(identify: "View")
static var caseDisplayRepresentations: [AppView : DisplayRepresentation] = [
.tab1: DisplayRepresentation(title: "Tab 1",
image: .init(systemName: "1.circle")),
.tab2: DisplayRepresentation(title: "Tab 2",
image: .init(systemName: "2.circle"))
]
}
// MARK: - Intent
struct OpenAppIntent: AppIntent {
static let title: LocalizedStringResource = "Open App"
static let description: IntentDescription = "Opens the app within the given view."
// Launches app when motion is triggered
static let openAppWhenRun: Bool = true
// App View Parameter
@Parameter(title: "View",
description: "The view contained in the app.",
default: .tab1,
requestValueDialog: "The place would you wish to navigate to?")
var view: AppView
// Shortcuts Motion Textual content
static var parameterSummary: some ParameterSummary {
Abstract("Open (.$view)")
}
@MainActor
func carry out() async throws -> some IntentResult {
if let url = URL(string: "myapp://(view)") {
await UIApplication.shared.open(url)
}
return .end result()
}
}