From 85af4b90e1e3858e043d0a94967c5301587c0ec3 Mon Sep 17 00:00:00 2001 From: Pat Winchell Date: Thu, 1 Jul 2021 20:25:50 -0700 Subject: [PATCH] Fix build error in Xcode 13. Change how MetricsCallbackWrapper wraps its value because enum cases with associated types can not be marked as unavailable with @available in Xcode 13/Swift 5.5 --- Sources/HTTPManager.swift | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/Sources/HTTPManager.swift b/Sources/HTTPManager.swift index 1802e42..c4b8f21 100644 --- a/Sources/HTTPManager.swift +++ b/Sources/HTTPManager.swift @@ -1761,27 +1761,22 @@ public final class HTTPManagerMetricsCallback: NSObject { // MARK: - Private -// Stored properties cannot be marked potentially unavailable with @unavailable. -// Therefore we will use a custom enum for this. -private enum MetricsCallbackWrapper { - case none - @available(iOS 10, macOS 10.12, tvOS 10, watchOS 3, *) - case some(HTTPManager.MetricsCallback) +// Wraps a `MetricsCallback` because stored properties cannot be marked potentially unavailable with @unavailable. +private struct MetricsCallbackWrapper { + static var none: MetricsCallbackWrapper { return MetricsCallbackWrapper() } + private var wrapped: Any? + @available(iOS 10, macOS 10.12, tvOS 10, watchOS 3, *) init(_ metricsCallback: HTTPManager.MetricsCallback?) { - switch metricsCallback { - case .none: self = .none - case .some(let value): self = .some(value) - } + wrapped = metricsCallback } + private init() {} + @available(iOS 10, macOS 10.12, tvOS 10, watchOS 3, *) var asOptional: HTTPManager.MetricsCallback? { - switch self { - case .none: return .none - case .some(let value): return .some(value) - } + return wrapped as? HTTPManager.MetricsCallback } }