I'm creating a code where someone scans a barcode, and it then sends them to a website by adding the EAN/UPC to the end of a URL. However, I am greeted with an error on line 37. I have no idea how to fix this 🤦🏻♂️, please help! Thanks in advance.
That's because the string is not valid for URL:
Link(destination:URL(string:"https://www.sites.google.com/view/planete-app/database/\(scannedCode)")!
You should print before and tell what you get.
print("https://www.sites.google.com/view/planete-app/database/\(scannedCode)")
to see what you get and test this URL directly in a browser
Maybe you have spaces in string.
Then replace
"https://www.sites.google.com/view/planete-app/database/\(scannedCode)"
by:
"https://www.sites.google.com/view/planete-app/database/\(scannedCode)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
Note: it is always risky to unwrap an optional without testing for nil