XCode errors when using Link in SwiftUI

I'm trying to use a Link in a swiftUI view, and like every tutorial online, I'd like to use this one:

Link(destination: URL, label: () -> View)

It pops up as one of the autocomplete options, but as soon as I add it to my code, I get these three errors:

  1. Extra arguments at positions #1, #2 in call

  2. Missing arguments for parameters 'rel', 'href', 'method' in call

  3. Static method 'buildExpression' requires that 'Link' conform to 'View'

It looks like XCode wants to force me to use this Link instead:

Link(rel: String, href: String, method: String)

but I don't understand why XCode won't let me use the first one. Does anyone know why this is happening?

Answered by KBartlett in 761771022

I figured out the issue - there was a custom Link struct in the app I'm working on that takes precedence. Using SwiftUI.Link fixed the issue.

Further explanation here: https://stackoverflow.com/questions/71698728/textfield-viewmodifier-not-conforming-to-viewmodifier

Accepted Answer

I figured out the issue - there was a custom Link struct in the app I'm working on that takes precedence. Using SwiftUI.Link fixed the issue.

Further explanation here: https://stackoverflow.com/questions/71698728/textfield-viewmodifier-not-conforming-to-viewmodifier

XCode errors when using Link in SwiftUI
 
 
Q