From 76b9d1da32b8e8a7cf18b1ec2a91b045a4617141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Buczek?= Date: Wed, 4 Sep 2024 04:49:05 +0200 Subject: [PATCH] Fix #3298: Add support for Xcode 16 (#3299) Task/Issue URL: #3298 & https://app.asana.com/0/414709148257752/1208200157992058/f Tech Design URL: CC: Description: Resolves #3298 This PR allows this repo to be compiled with Xcode 16. Two changes had to be made: In iOS 18 Apple added a new field to UIViewController named tab. It causes ambiguity and has to be renamed. Source https://developer.apple.com/documentation/uikit/uiviewcontroller/4434584-tab I renamed it to _tab, I am open to any other rename suggestion The URLOpener protocol and Apple's UIApplication shared the same signature for url opening function. This resulted in ambiguous compile time error. Code is now simplified and still allows to be used in mocks. Changes I made should be backwards compatible and work in Xcode 15 as well --- Core/URLOpener.swift | 8 +++---- DuckDuckGo/CriticalAlerts.swift | 4 ++-- DuckDuckGo/MainViewController+Email.swift | 2 +- DuckDuckGo/NewTabPageViewController.swift | 6 ++--- DuckDuckGo/NoMicPermissionAlert.swift | 2 +- DuckDuckGo/SettingsViewModel.swift | 24 +++++-------------- .../HeadlessWebViewCoordinator.swift | 2 +- .../SubscriptionSettingsViewModel.swift | 2 +- DuckDuckGo/SyncSettingsViewController.swift | 2 +- DuckDuckGo/TabViewController.swift | 2 +- DuckDuckGoTests/MockURLOpener.swift | 2 +- .../SyncUI/Views/SyncSettingsView.swift | 4 +--- 12 files changed, 22 insertions(+), 38 deletions(-) diff --git a/Core/URLOpener.swift b/Core/URLOpener.swift index d107c8a805..3bcdfb99ca 100644 --- a/Core/URLOpener.swift +++ b/Core/URLOpener.swift @@ -21,13 +21,11 @@ import UIKit public protocol URLOpener: AnyObject { func canOpenURL(_ url: URL) -> Bool - func open(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey: Any], completionHandler completion: ((Bool) -> Void)?) + func open(_ url: URL) } -public extension URLOpener { - func open(_ url: URL) { +extension UIApplication: URLOpener { + public func open(_ url: URL) { open(url, options: [:], completionHandler: nil) } } - -extension UIApplication: URLOpener {} diff --git a/DuckDuckGo/CriticalAlerts.swift b/DuckDuckGo/CriticalAlerts.swift index e9a5c9ebfb..7856f81756 100644 --- a/DuckDuckGo/CriticalAlerts.swift +++ b/DuckDuckGo/CriticalAlerts.swift @@ -43,7 +43,7 @@ struct CriticalAlerts { let openSettingsButton = UIAlertAction(title: UserText.insufficientDiskSpaceAction, style: .default) { _ in let url = URL(string: UIApplication.openSettingsURLString)! - UIApplication.shared.open(url, options: [:]) { _ in + UIApplication.shared.open(url) { _ in fatalError("App is in unrecoverable state") } } @@ -59,7 +59,7 @@ struct CriticalAlerts { let closeButton = UIAlertAction(title: UserText.keyCommandClose, style: .cancel) let signInButton = UIAlertAction(title: UserText.emailProtectionSignInAction, style: .default) { _ in - UIApplication.shared.open(URL.emailProtectionQuickLink, options: [:], completionHandler: nil) + UIApplication.shared.open(URL.emailProtectionQuickLink) } alertController.addAction(closeButton) diff --git a/DuckDuckGo/MainViewController+Email.swift b/DuckDuckGo/MainViewController+Email.swift index 8b4bb3421b..884068d937 100644 --- a/DuckDuckGo/MainViewController+Email.swift +++ b/DuckDuckGo/MainViewController+Email.swift @@ -26,7 +26,7 @@ extension MainViewController { func newEmailAddress() { guard emailManager.isSignedIn else { - UIApplication.shared.open(URL.emailProtectionQuickLink, options: [:], completionHandler: nil) + UIApplication.shared.open(URL.emailProtectionQuickLink) return } diff --git a/DuckDuckGo/NewTabPageViewController.swift b/DuckDuckGo/NewTabPageViewController.swift index 1a71aeacd6..bb11fcabfc 100644 --- a/DuckDuckGo/NewTabPageViewController.swift +++ b/DuckDuckGo/NewTabPageViewController.swift @@ -39,7 +39,7 @@ final class NewTabPageViewController: UIHostingController? @@ -53,7 +53,7 @@ final class NewTabPageViewController: UIHostingController Void)?) { + func open(_ url: URL) { didCallOpenURL = true capturedURL = url } diff --git a/LocalPackages/SyncUI/Sources/SyncUI/Views/SyncSettingsView.swift b/LocalPackages/SyncUI/Sources/SyncUI/Views/SyncSettingsView.swift index d8cd17d5ad..2a8edd6254 100644 --- a/LocalPackages/SyncUI/Sources/SyncUI/Views/SyncSettingsView.swift +++ b/LocalPackages/SyncUI/Sources/SyncUI/Views/SyncSettingsView.swift @@ -99,9 +99,7 @@ public struct SyncSettingsView: View { title: Text("Secure Your Device to Use Sync & Backup"), message: Text("A device password is required to use Sync & Backup."), dismissButton: .default(Text("Go to Settings"), action: { - UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, - options: [:], - completionHandler: nil) + UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!) model.shouldShowPasscodeRequiredAlert = false }) )