From 9146fb91137723329bbea767d789db11eec63fc8 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 20 Jun 2025 16:07:27 +0000 Subject: [PATCH 1/2] Refactor: Remove outdated availability and Swift version guards Analyzed project deployment targets and removed unnecessary @available, #available, and #if swift guards throughout the codebase. - iOS deployment target standardized at 15.0. - macOS deployment target baseline at 11.0. - tvOS deployment target baseline at 15.0. - watchOS deployment target baseline at 7.0. Removed #if swift(>=X.X) blocks by migrating the code for the newer Swift version into the enclosing scope and deleting the #else blocks. --- abtesting/Shared/AppConfig.swift | 1 - abtesting/Shared/ContentView.swift | 17 +- abtesting/Shared/UITests.swift | 8 +- analytics/AnalyticsExample/AppDelegate.swift | 10 +- .../AppDistributionExampleUITests.swift | 8 +- .../AppDelegate.swift | 1 - .../MainViewController.swift | 12 +- crashlytics/Shared/ContentView.swift | 23 +- crashlytics/Shared/UITests.swift | 8 +- .../Shared/Views/PostCell.swift | 16 +- .../UINavigationBar+Extension.swift | 10 +- .../FunctionsExampleSwift/AppDelegate.swift | 2 - .../PerformanceExample/Shared/Process.swift | 244 +++++++++--------- .../Shared/Views/ClassifyView.swift | 10 +- .../Shared/Views/DownloadView.swift | 10 +- .../Shared/Views/SaliencyMapView.swift | 10 +- .../Shared/Views/UploadView.swift | 10 +- 17 files changed, 161 insertions(+), 239 deletions(-) diff --git a/abtesting/Shared/AppConfig.swift b/abtesting/Shared/AppConfig.swift index b180eefe9..6eec11fa4 100644 --- a/abtesting/Shared/AppConfig.swift +++ b/abtesting/Shared/AppConfig.swift @@ -56,7 +56,6 @@ class AppConfig: ObservableObject { } #if compiler(>=5.5) && canImport(_Concurrency) - @available(iOS 15, tvOS 15, macOS 12, watchOS 8, *) func updateFromRemoteConfigAsync() async { let remoteConfig = RemoteConfig.remoteConfig() let oldValue = remoteConfig["color_scheme"].stringValue ?? "nil" diff --git a/abtesting/Shared/ContentView.swift b/abtesting/Shared/ContentView.swift index 5af7748e5..0ff10d95d 100644 --- a/abtesting/Shared/ContentView.swift +++ b/abtesting/Shared/ContentView.swift @@ -40,18 +40,11 @@ struct FirebaseList: View { var body: some View { VStack { #if compiler(>=5.5) && canImport(_Concurrency) - if #available(iOS 15, tvOS 15, macOS 12, watchOS 8, *) { - BasicList(data: data) - .preferredColorScheme(appConfig.colorScheme) - .foregroundColor(appConfig.colorScheme == .dark ? .orange : .primary) - .task { await appConfig.updateFromRemoteConfigAsync() } - .refreshable { await appConfig.updateFromRemoteConfigAsync() } - } else { - BasicList(data: data) - .preferredColorScheme(appConfig.colorScheme) - .foregroundColor(appConfig.colorScheme == .dark ? .orange : .primary) - .onAppear { appConfig.updateFromRemoteConfig() } - } + BasicList(data: data) + .preferredColorScheme(appConfig.colorScheme) + .foregroundColor(appConfig.colorScheme == .dark ? .orange : .primary) + .task { await appConfig.updateFromRemoteConfigAsync() } + .refreshable { await appConfig.updateFromRemoteConfigAsync() } #else BasicList(data: data) .preferredColorScheme(appConfig.colorScheme) diff --git a/abtesting/Shared/UITests.swift b/abtesting/Shared/UITests.swift index 90fd525d6..c08fc5746 100644 --- a/abtesting/Shared/UITests.swift +++ b/abtesting/Shared/UITests.swift @@ -102,11 +102,9 @@ class UITests: XCTestCase { } func testLaunchPerformance() throws { - if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) { - // This measures how long it takes to launch your application. - measure(metrics: [XCTApplicationLaunchMetric()]) { - XCUIApplication().launch() - } + // This measures how long it takes to launch your application. + measure(metrics: [XCTApplicationLaunchMetric()]) { + XCUIApplication().launch() } } } diff --git a/analytics/AnalyticsExample/AppDelegate.swift b/analytics/AnalyticsExample/AppDelegate.swift index f0eb5f217..3f86c0f80 100644 --- a/analytics/AnalyticsExample/AppDelegate.swift +++ b/analytics/AnalyticsExample/AppDelegate.swift @@ -30,13 +30,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate { didFinishLaunchingWithOptions launchOptions: [UIApplication .LaunchOptionsKey: Any]?) -> Bool { FirebaseApp.configure() - if #available(iOS 14, *) { - SKPaymentQueue.default().add(FirebaseApp.app()!) - print("\(SKPaymentQueue.default().transactionObservers as [AnyObject])") + SKPaymentQueue.default().add(FirebaseApp.app()!) + print("\(SKPaymentQueue.default().transactionObservers as [AnyObject])") - (SKPaymentQueue.default().transactionObservers as [AnyObject]).forEach { - print($0) - } + (SKPaymentQueue.default().transactionObservers as [AnyObject]).forEach { + print($0) } print("done") return true diff --git a/appdistribution/AppDistributionUITests/AppDistributionExampleUITests.swift b/appdistribution/AppDistributionUITests/AppDistributionExampleUITests.swift index bf0c827cc..583434a24 100644 --- a/appdistribution/AppDistributionUITests/AppDistributionExampleUITests.swift +++ b/appdistribution/AppDistributionUITests/AppDistributionExampleUITests.swift @@ -36,11 +36,9 @@ class AppDistributionExampleUITests: XCTestCase { } func testLaunchPerformance() throws { - if #available(macOS 10.15, iOS 13.0, tvOS 13.0, *) { - // This measures how long it takes to launch your application. - measure(metrics: [XCTOSSignpostMetric.applicationLaunch]) { - XCUIApplication().launch() - } + // This measures how long it takes to launch your application. + measure(metrics: [XCTOSSignpostMetric.applicationLaunch]) { + XCUIApplication().launch() } } } diff --git a/authentication/LegacyAuthQuickstart/AuthenticationExampleSwift/AppDelegate.swift b/authentication/LegacyAuthQuickstart/AuthenticationExampleSwift/AppDelegate.swift index ec762c4bf..367109892 100644 --- a/authentication/LegacyAuthQuickstart/AuthenticationExampleSwift/AppDelegate.swift +++ b/authentication/LegacyAuthQuickstart/AuthenticationExampleSwift/AppDelegate.swift @@ -48,7 +48,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } // [START new_delegate] - @available(iOS 9.0, *) func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any]) -> Bool { diff --git a/authentication/LegacyAuthQuickstart/AuthenticationExampleSwift/MainViewController.swift b/authentication/LegacyAuthQuickstart/AuthenticationExampleSwift/MainViewController.swift index 71ab339e6..1f5530d63 100644 --- a/authentication/LegacyAuthQuickstart/AuthenticationExampleSwift/MainViewController.swift +++ b/authentication/LegacyAuthQuickstart/AuthenticationExampleSwift/MainViewController.swift @@ -160,12 +160,8 @@ class MainViewController: UITableViewController { } } case .authApple: - if #available(iOS 13, *) { - action = UIAlertAction(title: "Apple", style: .default) { UIAlertAction in - self.startSignInWithAppleFlow() - } - } else { - continue + action = UIAlertAction(title: "Apple", style: .default) { UIAlertAction in + self.startSignInWithAppleFlow() } case .authFacebook: action = UIAlertAction(title: "Facebook", style: .default) { UIAlertAction in @@ -1026,7 +1022,6 @@ class MainViewController: UITableViewController { // Unhashed nonce. fileprivate var currentNonce: String? - @available(iOS 13, *) func startSignInWithAppleFlow() { let nonce = randomNonceString() currentNonce = nonce @@ -1066,7 +1061,6 @@ class MainViewController: UITableViewController { // [END random_nonce] // [START sha_256] - @available(iOS 13, *) private func sha256(_ input: String) -> String { let inputData = Data(input.utf8) let hashedData = SHA256.hash(data: inputData) @@ -1080,7 +1074,6 @@ class MainViewController: UITableViewController { // [END sha_256] } -@available(iOS 13.0, *) extension MainViewController: ASAuthorizationControllerDelegate { func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) { @@ -1113,7 +1106,6 @@ extension MainViewController: ASAuthorizationControllerDelegate { } } -@available(iOS 13.0, *) extension MainViewController: ASAuthorizationControllerPresentationContextProviding { func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor { return view.window! diff --git a/crashlytics/Shared/ContentView.swift b/crashlytics/Shared/ContentView.swift index 588528fc5..ef32f7d62 100644 --- a/crashlytics/Shared/ContentView.swift +++ b/crashlytics/Shared/ContentView.swift @@ -34,7 +34,7 @@ struct ContentView: View { private var crashlyticsReference = Crashlytics.crashlytics() #if compiler(>=5.5) && canImport(_Concurrency) - @available(iOS 15, tvOS 15, macOS 12, watchOS 8, *) func checkForUnsentReportsAsync() async { + func checkForUnsentReportsAsync() async { let reportFound = await crashlyticsReference.checkForUnsentReports() if reportFound { crashlyticsReference.sendUnsentReports() @@ -51,24 +51,17 @@ struct ContentView: View { } var body: some View { - if #available(iOS 15, tvOS 15, macOS 12, watchOS 8, *) { - #if compiler(>=5.5) && canImport(_Concurrency) - CrashButtonView() - .task { - await self.checkForUnsentReportsAsync() - } - #else - CrashButtonView() - .onAppear { - self.checkForUnsentReports() - } - #endif - } else { + #if compiler(>=5.5) && canImport(_Concurrency) + CrashButtonView() + .task { + await self.checkForUnsentReportsAsync() + } + #else CrashButtonView() .onAppear { self.checkForUnsentReports() } - } + #endif } } diff --git a/crashlytics/Shared/UITests.swift b/crashlytics/Shared/UITests.swift index e980172a5..690d8a9e3 100644 --- a/crashlytics/Shared/UITests.swift +++ b/crashlytics/Shared/UITests.swift @@ -36,11 +36,9 @@ class UITests: XCTestCase { } func testLaunchPerformance() throws { - if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) { - // This measures how long it takes to launch your application. - measure(metrics: [XCTApplicationLaunchMetric()]) { - XCUIApplication().launch() - } + // This measures how long it takes to launch your application. + measure(metrics: [XCTApplicationLaunchMetric()]) { + XCUIApplication().launch() } } } diff --git a/database/DatabaseExampleSwiftUI/DatabaseExample/Shared/Views/PostCell.swift b/database/DatabaseExampleSwiftUI/DatabaseExample/Shared/Views/PostCell.swift index 3ff6d8a89..21e8e4a2f 100644 --- a/database/DatabaseExampleSwiftUI/DatabaseExample/Shared/Views/PostCell.swift +++ b/database/DatabaseExampleSwiftUI/DatabaseExample/Shared/Views/PostCell.swift @@ -31,17 +31,13 @@ struct PostCell: View { #if os(iOS) || os(macOS) starButton .onTapGesture { - if #available(iOS 15, macOS 12, *) { - #if compiler(>=5.5) && canImport(_Concurrency) - Task { await - post.didTapStarButtonAsync() - } - #else - post.didTapStarButton() - #endif - } else { + #if compiler(>=5.5) && canImport(_Concurrency) + Task { await + post.didTapStarButtonAsync() + } + #else post.didTapStarButton() - } + #endif } #elseif os(tvOS) starButton diff --git a/firestore/FirestoreExample/UINavigationBar+Extension.swift b/firestore/FirestoreExample/UINavigationBar+Extension.swift index 9d80c789c..d658d0a78 100644 --- a/firestore/FirestoreExample/UINavigationBar+Extension.swift +++ b/firestore/FirestoreExample/UINavigationBar+Extension.swift @@ -20,7 +20,6 @@ extension UINavigationBar { static let firebaseTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] - @available(iOS 13.0, *) var firebaseNavigationBarAppearance: UINavigationBarAppearance { let navBarAppearance = UINavigationBarAppearance() navBarAppearance.configureWithOpaqueBackground() @@ -29,14 +28,11 @@ extension UINavigationBar { return navBarAppearance } - @available(iOS 13.0, *) func applyAppearance(_ appearance: UINavigationBarAppearance) { standardAppearance = appearance compactAppearance = appearance scrollEdgeAppearance = appearance - if #available(iOS 15.0, *) { - compactScrollEdgeAppearance = appearance - } + compactScrollEdgeAppearance = appearance } func applyFirebaseAppearance() { @@ -44,8 +40,6 @@ extension UINavigationBar { isTranslucent = false titleTextAttributes = UINavigationBar.firebaseTitleTextAttributes - if #available(iOS 13.0, *) { - applyAppearance(firebaseNavigationBarAppearance) - } + applyAppearance(firebaseNavigationBarAppearance) } } diff --git a/functions/LegacyFunctionsQuickstart/FunctionsExampleSwift/AppDelegate.swift b/functions/LegacyFunctionsQuickstart/FunctionsExampleSwift/AppDelegate.swift index 7aaa95c4e..494b6d439 100644 --- a/functions/LegacyFunctionsQuickstart/FunctionsExampleSwift/AppDelegate.swift +++ b/functions/LegacyFunctionsQuickstart/FunctionsExampleSwift/AppDelegate.swift @@ -41,7 +41,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { return true } - @available(iOS 9.0, *) func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any]) -> Bool { guard let sourceApplication = @@ -51,7 +50,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { return handleOpenUrl(url, sourceApplication: sourceApplication) } - @available(iOS 8.0, *) func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool { return handleOpenUrl(url, sourceApplication: sourceApplication) diff --git a/performance/SwiftUIPerformanceQuickstart/PerformanceExample/Shared/Process.swift b/performance/SwiftUIPerformanceQuickstart/PerformanceExample/Shared/Process.swift index 0e5fa6652..ce5db8d6e 100644 --- a/performance/SwiftUIPerformanceQuickstart/PerformanceExample/Shared/Process.swift +++ b/performance/SwiftUIPerformanceQuickstart/PerformanceExample/Shared/Process.swift @@ -38,161 +38,159 @@ class Process: ObservableObject { let precision: Float = 0.2 let site = "https://firebase.google.com/downloads/brand-guidelines/PNG/logo-logomark.png" - #if swift(>=5.5) - @MainActor @available(iOS 15, tvOS 15,*) - func updateStatusAsync(to newStatus: ProcessStatus, updateUploadStatus: Bool = false) { - status = newStatus - if updateUploadStatus { uploadSucceeded = newStatus == .success(.upload) } - } + @MainActor + func updateStatusAsync(to newStatus: ProcessStatus, updateUploadStatus: Bool = false) { + status = newStatus + if updateUploadStatus { uploadSucceeded = newStatus == .success(.upload) } + } - @MainActor @available(iOS 15, tvOS 15, *) func updateImageAsync(to newImage: UIImage?) { - image = newImage - } + @MainActor func updateImageAsync(to newImage: UIImage?) { + image = newImage + } + + @MainActor + func updateSaliencyMapAsync(to newSaliencyMap: UIImage?) { + saliencyMap = newSaliencyMap + } + + func downloadImageAsync() async { + await updateStatusAsync(to: .running(.download)) - @MainActor @available(iOS 15, tvOS 15, *) - func updateSaliencyMapAsync(to newSaliencyMap: UIImage?) { - saliencyMap = newSaliencyMap + guard let url = URL(string: site) else { + await updateStatusAsync(to: .failure(.download)) + print("Failure obtaining URL.") + return } - @available(iOS 15, tvOS 15, *) func downloadImageAsync() async { - await updateStatusAsync(to: .running(.download)) + do { + let (data, response) = try await URLSession.shared.data(from: url) - guard let url = URL(string: site) else { + guard let httpResponse = response as? HTTPURLResponse, + (200 ... 299).contains(httpResponse.statusCode) else { + print("Did not receive acceptable response: \(response)") await updateStatusAsync(to: .failure(.download)) - print("Failure obtaining URL.") return } - do { - let (data, response) = try await URLSession.shared.data(from: url) - - guard let httpResponse = response as? HTTPURLResponse, - (200 ... 299).contains(httpResponse.statusCode) else { - print("Did not receive acceptable response: \(response)") - await updateStatusAsync(to: .failure(.download)) - return - } - - guard let mimeType = httpResponse.mimeType, mimeType == "image/png", - let image = UIImage(data: data) else { - print("Could not create image from downloaded data.") - await updateStatusAsync(to: .failure(.download)) - return - } - - await updateStatusAsync(to: .success(.download)) - await updateImageAsync(to: image) - - } catch { - print("Error downloading image: \(error).") + guard let mimeType = httpResponse.mimeType, mimeType == "image/png", + let image = UIImage(data: data) else { + print("Could not create image from downloaded data.") await updateStatusAsync(to: .failure(.download)) - } - } - - @available(iOS 15, tvOS 15, *) func classifyImageAsync() async { - guard let uiImage = image, let ciImage = CIImage(image: uiImage) else { - print("Could not convert image into correct format.") - await updateStatusAsync(to: .failure(.classify)) return } - let handler = VNImageRequestHandler(ciImage: ciImage, options: [:]) - let request = VNClassifyImageRequest() - await updateStatusAsync(to: .running(.classify)) - let trace = makeTrace(called: "Classification") - trace?.start() - try? handler.perform([request]) - trace?.stop() + await updateStatusAsync(to: .success(.download)) + await updateImageAsync(to: image) - guard let observations = request.results else { - print("Failed to obtain classification results.") - await updateStatusAsync(to: .failure(.classify)) - return - } + } catch { + print("Error downloading image: \(error).") + await updateStatusAsync(to: .failure(.download)) + } + } - categories = observations - .filter { $0.hasMinimumRecall(0.01, forPrecision: precision) } - .map { ($0.identifier, $0.confidence) } + func classifyImageAsync() async { + guard let uiImage = image, let ciImage = CIImage(image: uiImage) else { + print("Could not convert image into correct format.") + await updateStatusAsync(to: .failure(.classify)) + return + } - await updateStatusAsync(to: .success(.classify)) + let handler = VNImageRequestHandler(ciImage: ciImage, options: [:]) + let request = VNClassifyImageRequest() + await updateStatusAsync(to: .running(.classify)) + let trace = makeTrace(called: "Classification") + trace?.start() + try? handler.perform([request]) + trace?.stop() + + guard let observations = request.results else { + print("Failed to obtain classification results.") + await updateStatusAsync(to: .failure(.classify)) + return } - @available(iOS 15, tvOS 15, *) func generateSaliencyMapAsync() async { - guard let uiImage = image, let ciImage = CIImage(image: uiImage) else { - print("Could not convert image into correct format.") - await updateStatusAsync(to: .failure(.saliencyMap)) - return - } + categories = observations + .filter { $0.hasMinimumRecall(0.01, forPrecision: precision) } + .map { ($0.identifier, $0.confidence) } - let handler = VNImageRequestHandler(ciImage: ciImage, options: [:]) - let request = VNGenerateAttentionBasedSaliencyImageRequest() - await updateStatusAsync(to: .running(.saliencyMap)) - let trace = makeTrace(called: "Saliency_Map") - trace?.start() - try? handler.perform([request]) - trace?.stop() + await updateStatusAsync(to: .success(.classify)) + } - guard let observation = request.results?.first else { - print("Failed to generate saliency map.") - await updateStatusAsync(to: .failure(.saliencyMap)) - return - } + func generateSaliencyMapAsync() async { + guard let uiImage = image, let ciImage = CIImage(image: uiImage) else { + print("Could not convert image into correct format.") + await updateStatusAsync(to: .failure(.saliencyMap)) + return + } - let inputImage = CIImage(cvPixelBuffer: observation.pixelBuffer) - let scale = Double(ciImage.extent.height) / Double(inputImage.extent.height) - let aspectRatio = Double(ciImage.extent.width) / Double(ciImage.extent.height) + let handler = VNImageRequestHandler(ciImage: ciImage, options: [:]) + let request = VNGenerateAttentionBasedSaliencyImageRequest() + await updateStatusAsync(to: .running(.saliencyMap)) + let trace = makeTrace(called: "Saliency_Map") + trace?.start() + try? handler.perform([request]) + trace?.stop() - guard let scaleFilter = CIFilter(name: "CILanczosScaleTransform") else { - print("Failed to create scaling filter.") - await updateStatusAsync(to: .failure(.saliencyMap)) - return - } + guard let observation = request.results?.first else { + print("Failed to generate saliency map.") + await updateStatusAsync(to: .failure(.saliencyMap)) + return + } - scaleFilter.setValue(inputImage, forKey: kCIInputImageKey) - scaleFilter.setValue(scale, forKey: kCIInputScaleKey) - scaleFilter.setValue(aspectRatio, forKey: kCIInputAspectRatioKey) + let inputImage = CIImage(cvPixelBuffer: observation.pixelBuffer) + let scale = Double(ciImage.extent.height) / Double(inputImage.extent.height) + let aspectRatio = Double(ciImage.extent.width) / Double(ciImage.extent.height) - guard let scaledImage = scaleFilter.outputImage else { - print("Failed to scale saliency map.") - await updateStatusAsync(to: .failure(.saliencyMap)) - return - } + guard let scaleFilter = CIFilter(name: "CILanczosScaleTransform") else { + print("Failed to create scaling filter.") + await updateStatusAsync(to: .failure(.saliencyMap)) + return + } - let saliencyImage = context.createCGImage(scaledImage, from: scaledImage.extent) + scaleFilter.setValue(inputImage, forKey: kCIInputImageKey) + scaleFilter.setValue(scale, forKey: kCIInputScaleKey) + scaleFilter.setValue(aspectRatio, forKey: kCIInputAspectRatioKey) - guard let saliencyMap = saliencyImage else { - print("Failed to convert saliency map to correct format.") - await updateStatusAsync(to: .failure(.saliencyMap)) - return - } + guard let scaledImage = scaleFilter.outputImage else { + print("Failed to scale saliency map.") + await updateStatusAsync(to: .failure(.saliencyMap)) + return + } + + let saliencyImage = context.createCGImage(scaledImage, from: scaledImage.extent) - await updateSaliencyMapAsync(to: UIImage(cgImage: saliencyMap)) - await updateStatusAsync(to: .success(.saliencyMap)) + guard let saliencyMap = saliencyImage else { + print("Failed to convert saliency map to correct format.") + await updateStatusAsync(to: .failure(.saliencyMap)) + return } - @available(iOS 15, tvOS 15, *) - func uploadSaliencyMapAsync(compressionQuality: CGFloat = 0.5) async { - guard let jpg = saliencyMap?.jpegData(compressionQuality: compressionQuality) else { - print("Could not convert saliency map into correct format.") - await updateStatusAsync(to: .failure(.upload), updateUploadStatus: true) - return - } + await updateSaliencyMapAsync(to: UIImage(cgImage: saliencyMap)) + await updateStatusAsync(to: .success(.saliencyMap)) + } - let metadata = StorageMetadata() - metadata.contentType = "image/jpeg" - let reference = Storage.storage().reference().child("saliency_map.jpg") - await updateStatusAsync(to: .running(.upload)) - do { - let response = try await reference.putDataAsync(jpg, metadata: metadata) - print("Upload response metadata: \(response)") - await updateStatusAsync(to: .success(.upload), updateUploadStatus: true) - } catch { - print("Error uploading saliency map: \(error).") - await updateStatusAsync(to: .failure(.upload), updateUploadStatus: true) - } + func uploadSaliencyMapAsync(compressionQuality: CGFloat = 0.5) async { + guard let jpg = saliencyMap?.jpegData(compressionQuality: compressionQuality) else { + print("Could not convert saliency map into correct format.") + await updateStatusAsync(to: .failure(.upload), updateUploadStatus: true) + return } - #endif + + let metadata = StorageMetadata() + metadata.contentType = "image/jpeg" + let reference = Storage.storage().reference().child("saliency_map.jpg") + await updateStatusAsync(to: .running(.upload)) + + do { + let response = try await reference.putDataAsync(jpg, metadata: metadata) + print("Upload response metadata: \(response)") + await updateStatusAsync(to: .success(.upload), updateUploadStatus: true) + } catch { + print("Error uploading saliency map: \(error).") + await updateStatusAsync(to: .failure(.upload), updateUploadStatus: true) + } + } func updateStatus(to newStatus: ProcessStatus, updateUploadStatus: Bool = false) { DispatchQueue.main.async { diff --git a/performance/SwiftUIPerformanceQuickstart/PerformanceExample/Shared/Views/ClassifyView.swift b/performance/SwiftUIPerformanceQuickstart/PerformanceExample/Shared/Views/ClassifyView.swift index 89fd27b9d..505ee9bae 100644 --- a/performance/SwiftUIPerformanceQuickstart/PerformanceExample/Shared/Views/ClassifyView.swift +++ b/performance/SwiftUIPerformanceQuickstart/PerformanceExample/Shared/Views/ClassifyView.swift @@ -37,15 +37,7 @@ struct ClassifyView: View { } else { Button("Classify Image") { if !process.isRunning { - if #available(iOS 15, tvOS 15, *) { - #if swift(>=5.5) - Task { await process.classifyImageAsync() } - #else - process.classifyImage() - #endif - } else { - process.classifyImage() - } + Task { await process.classifyImageAsync() } } } .disabled(process.isRunning) diff --git a/performance/SwiftUIPerformanceQuickstart/PerformanceExample/Shared/Views/DownloadView.swift b/performance/SwiftUIPerformanceQuickstart/PerformanceExample/Shared/Views/DownloadView.swift index cf2ed06fa..e39d850f6 100644 --- a/performance/SwiftUIPerformanceQuickstart/PerformanceExample/Shared/Views/DownloadView.swift +++ b/performance/SwiftUIPerformanceQuickstart/PerformanceExample/Shared/Views/DownloadView.swift @@ -32,15 +32,7 @@ struct DownloadView: View { .padding(.bottom) Button("Download Image") { if !process.isRunning { - if #available(iOS 15, tvOS 15, *) { - #if swift(>=5.5) - Task { await process.downloadImageAsync() } - #else - process.downloadImage() - #endif - } else { - process.downloadImage() - } + Task { await process.downloadImageAsync() } } } .disabled(process.isRunning) diff --git a/performance/SwiftUIPerformanceQuickstart/PerformanceExample/Shared/Views/SaliencyMapView.swift b/performance/SwiftUIPerformanceQuickstart/PerformanceExample/Shared/Views/SaliencyMapView.swift index f30bac088..eebe2c7ae 100644 --- a/performance/SwiftUIPerformanceQuickstart/PerformanceExample/Shared/Views/SaliencyMapView.swift +++ b/performance/SwiftUIPerformanceQuickstart/PerformanceExample/Shared/Views/SaliencyMapView.swift @@ -30,15 +30,7 @@ struct SaliencyMapView: View { Image(uiImage: image).padding(.bottom) Button("Generate Saliency Map") { if !process.isRunning { - if #available(iOS 15, tvOS 15, *) { - #if swift(>=5.5) - Task { await process.generateSaliencyMapAsync() } - #else - process.generateSaliencyMap() - #endif - } else { - process.generateSaliencyMap() - } + Task { await process.generateSaliencyMapAsync() } } } .disabled(process.isRunning) diff --git a/performance/SwiftUIPerformanceQuickstart/PerformanceExample/Shared/Views/UploadView.swift b/performance/SwiftUIPerformanceQuickstart/PerformanceExample/Shared/Views/UploadView.swift index 5bdaa13b9..210dc5332 100644 --- a/performance/SwiftUIPerformanceQuickstart/PerformanceExample/Shared/Views/UploadView.swift +++ b/performance/SwiftUIPerformanceQuickstart/PerformanceExample/Shared/Views/UploadView.swift @@ -29,15 +29,7 @@ struct UploadView: View { } else { Button("Upload Saliency Map") { if !process.isRunning { - if #available(iOS 15, tvOS 15, *) { - #if swift(>=5.5) - Task { await process.uploadSaliencyMapAsync() } - #else - process.uploadSaliencyMap() - #endif - } else { - process.uploadSaliencyMap() - } + Task { await process.uploadSaliencyMapAsync() } } } .disabled(process.isRunning) From 7af22c6480b48254d9dfd52b73904ece61607c15 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 20 Jun 2025 17:02:45 +0000 Subject: [PATCH 2/2] Refactor: Remove #if compiler directives Removed #if compiler(>=X.X) directives by keeping the code within the #if block and removing the #else and #endif blocks. This assumes the codebase is compiled with a modern Swift compiler where these conditional blocks are no longer necessary. --- abtesting/Shared/AppConfig.swift | 1 - abtesting/Shared/ContentView.swift | 7 ------- crashlytics/Shared/ContentView.swift | 9 --------- .../DatabaseExample/Shared/Views/PostCell.swift | 4 ---- 4 files changed, 21 deletions(-) diff --git a/abtesting/Shared/AppConfig.swift b/abtesting/Shared/AppConfig.swift index 6eec11fa4..462beb730 100644 --- a/abtesting/Shared/AppConfig.swift +++ b/abtesting/Shared/AppConfig.swift @@ -55,7 +55,6 @@ class AppConfig: ObservableObject { } } - #if compiler(>=5.5) && canImport(_Concurrency) func updateFromRemoteConfigAsync() async { let remoteConfig = RemoteConfig.remoteConfig() let oldValue = remoteConfig["color_scheme"].stringValue ?? "nil" diff --git a/abtesting/Shared/ContentView.swift b/abtesting/Shared/ContentView.swift index 0ff10d95d..ff3586d65 100644 --- a/abtesting/Shared/ContentView.swift +++ b/abtesting/Shared/ContentView.swift @@ -39,18 +39,11 @@ struct FirebaseList: View { ] var body: some View { VStack { - #if compiler(>=5.5) && canImport(_Concurrency) BasicList(data: data) .preferredColorScheme(appConfig.colorScheme) .foregroundColor(appConfig.colorScheme == .dark ? .orange : .primary) .task { await appConfig.updateFromRemoteConfigAsync() } .refreshable { await appConfig.updateFromRemoteConfigAsync() } - #else - BasicList(data: data) - .preferredColorScheme(appConfig.colorScheme) - .foregroundColor(appConfig.colorScheme == .dark ? .orange : .primary) - .onAppear { appConfig.updateFromRemoteConfig() } - #endif Button("Refresh") { appConfig.updateFromRemoteConfig() } Spacer() } diff --git a/crashlytics/Shared/ContentView.swift b/crashlytics/Shared/ContentView.swift index ef32f7d62..56397fbae 100644 --- a/crashlytics/Shared/ContentView.swift +++ b/crashlytics/Shared/ContentView.swift @@ -33,14 +33,12 @@ struct CrashButtonView: View { struct ContentView: View { private var crashlyticsReference = Crashlytics.crashlytics() - #if compiler(>=5.5) && canImport(_Concurrency) func checkForUnsentReportsAsync() async { let reportFound = await crashlyticsReference.checkForUnsentReports() if reportFound { crashlyticsReference.sendUnsentReports() } } - #endif func checkForUnsentReports() { crashlyticsReference.checkForUnsentReports { reportFound in @@ -51,17 +49,10 @@ struct ContentView: View { } var body: some View { - #if compiler(>=5.5) && canImport(_Concurrency) CrashButtonView() .task { await self.checkForUnsentReportsAsync() } - #else - CrashButtonView() - .onAppear { - self.checkForUnsentReports() - } - #endif } } diff --git a/database/DatabaseExampleSwiftUI/DatabaseExample/Shared/Views/PostCell.swift b/database/DatabaseExampleSwiftUI/DatabaseExample/Shared/Views/PostCell.swift index 21e8e4a2f..fb5a2afea 100644 --- a/database/DatabaseExampleSwiftUI/DatabaseExample/Shared/Views/PostCell.swift +++ b/database/DatabaseExampleSwiftUI/DatabaseExample/Shared/Views/PostCell.swift @@ -31,13 +31,9 @@ struct PostCell: View { #if os(iOS) || os(macOS) starButton .onTapGesture { - #if compiler(>=5.5) && canImport(_Concurrency) Task { await post.didTapStarButtonAsync() } - #else - post.didTapStarButton() - #endif } #elseif os(tvOS) starButton