I'm getting into a crash only with iOS14 and Xcode 14 simulator. I don't see this issue when I was on iOS13 or Xcode 13 simulator.
I'm using SafariServices to open a URL and the crash is happening at
SafariView(url: URL(string: self.urlString)!)
I felt fine forcing the unwrap because I know that self.urlString = self.dogood.link has a value from an Identifiable that I'm using. Am I looking at an iOS 14 bug possibly?
I'm using SafariServices to open a URL and the crash is happening at
SafariView(url: URL(string: self.urlString)!)
I felt fine forcing the unwrap because I know that self.urlString = self.dogood.link has a value from an Identifiable that I'm using. Am I looking at an iOS 14 bug possibly?
Code Block struct SafariView: UIViewControllerRepresentable { typealias UIViewControllerType = SFSafariViewController var url: URL? func makeUIViewController(context: UIViewControllerRepresentableContext<SafariView>) -> SFSafariViewController { return SFSafariViewController(url: url!) } func updateUIViewController(_ safariViewController: SFSafariViewController, context: UIViewControllerRepresentableContext<SafariView>) { } }
Code Block struct DoGoodListView: View { @State private var showSafari = false @State private var urlString = "" var dogood: DoGood var body: some View { VStack(spacing: 8.0) { HStack { Text(dogood.name) .font(.title).bold() Spacer() Image(dogood.logo) .resizable() .aspectRatio(contentMode: .fit) .cornerRadius(15) .frame(width: 50, height: 50) } Text(dogood.info) Button(action: { self.urlString = self.dogood.link self.showSafari = true print(self.urlString) }) { Text("Visit") .font(.system(size: 18, weight: .medium)) .frame(width: 250, height: 50) .background(Color("card3")) .clipShape(RoundedRectangle(cornerRadius: 30, style: .continuous)) .shadow(color: Color("card3").opacity(0.1), radius: 1, x: 0, y: 1) .shadow(color: Color("card3").opacity(0.2), radius: 10, x: 0, y: 10) .padding() } .sheet(isPresented: $showSafari) { SafariView(url: URL(string: self.urlString)!) } } } }
Seems you have hit the same issue shown in this thread
Try passing a Binding.
Try passing a Binding.
Code Block struct SafariView: UIViewControllerRepresentable { typealias UIViewControllerType = SFSafariViewController @Binding var urlString: String func makeUIViewController(context: UIViewControllerRepresentableContext<SafariView>) -> SFSafariViewController { guard let url = URL(string: urlString) else { fatalError("Invalid urlString: \(urlString)") } return SFSafariViewController(url: url) } func updateUIViewController(_ safariViewController: SFSafariViewController, context: UIViewControllerRepresentableContext<SafariView>) { } }
Code Block struct DoGoodListView: View { @State private var showSafari = false @State private var urlString = "" var dogood: DoGood var body: some View { VStack(spacing: 8.0) { ... .sheet(isPresented: $showSafari) { SafariView(urlString: self.$urlString) } } } }