.navigationDestination(for: Element.self) { element in
if let urlString = element.link?.externalUrlString, let url = URL(string: urlString) {
openURL(url)
}
}
I get below error: 'buildExpression' is unavailable: this expression does not conform to 'View'
.navigationDestination(for: Element.self) { element in
if let urlString = element.link?.externalUrlString, let url = URL(string: urlString) {
openURL(url)
}
}
Share Improve this question asked Mar 20 at 15:08 AppleDeveloperAppleDeveloper 1,4593 gold badges21 silver badges52 bronze badges 2 |I get below error: 'buildExpression' is unavailable: this expression does not conform to 'View'
1 Answer
Reset to default 1An external URL is not a "navigation destination". You should replace the NavigationLink
NavigationLink("Some Title", value: someElement)
with a Button
:
Button("Some Title") {
if let urlString = element.link?.externalUrlString, let url = URL(string: urlString) {
openURL(url)
}
}
If the NavigationLink
was originally in a List
, and you want to keep the trailing chevron, see SwiftUI List disclosure indicator without NavigationLink.
If you want to navigate to a SFSafariViewController
that shows that URL, see How do I use SFSafariViewController with SwiftUI?.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744400817a4572376.html
SFSafariViewController
or something? Otherwise, just use a button and callopenURL
in its action. – Sweeper Commented Mar 20 at 15:10