I have this code below
import SwiftUI
struct MyView: View {
let text = "If you want to know more, ***[Click Here](http://example.com)*** to continue"
@Environment(\.openURL) private var openURL
var body: some View {
Text(LocalizedString(text))
.environment(\.openURL, OpenURLAction{ url in
print(url)
return .systemAction
})
}
}
I saw this in OpenURLAction Documentation and other SO questions like This answer from workingdog support Ukraine
But I always get a runtime error from Xcode saying:
Key path value type 'WritableKeyPath<EnvironmentValues, OpenURLAction>' cannot be converted to contextual type 'KeyPath<EnvironmentValues, OpenURLAction>'
Please can some one tell me what's going wrong? I'm using Xcode 14.0.1 if needed
Note: My reason for this is that the URLs associated with the text are not valid URLs, for example, I have a URL like this "[John Doe](friend-4-2)"
, so I want to open another ViewController in my app depending on the particular link the user clicked
Below is an image showing how my code looks like and the error I get