Skip to content

Commit

Permalink
Remove redundant @available and #available annotations (#3616)
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoSoto committed Feb 14, 2024
1 parent f04d60d commit 5aef999
Show file tree
Hide file tree
Showing 231 changed files with 170 additions and 3,805 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import Foundation
import RevenueCat

@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *)
final class TrialOrIntroEligibilityChecker: ObservableObject {

typealias Checker = @Sendable ([Package]) async -> [Package: IntroEligibilityStatus]
Expand Down Expand Up @@ -49,7 +48,6 @@ final class TrialOrIntroEligibilityChecker: ObservableObject {

}

@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *)
extension TrialOrIntroEligibilityChecker {

func eligibility(for package: Package) async -> IntroEligibilityStatus {
Expand All @@ -63,7 +61,6 @@ extension TrialOrIntroEligibilityChecker {

}

@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *)
extension StoreProduct {

var hasIntroDiscount: Bool {
Expand Down
2 changes: 0 additions & 2 deletions RevenueCatUI/Data/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import RevenueCat

// swiftlint:disable identifier_name

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
enum Strings {

case package_not_subscription(Package)
Expand All @@ -42,7 +41,6 @@ enum Strings {

}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
extension Strings: CustomStringConvertible {

var description: String {
Expand Down
3 changes: 0 additions & 3 deletions RevenueCatUI/Data/UserInterfaceIdiom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ extension UserInterfaceIdiom {

}

@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *)
extension EnvironmentValues {

var userInterfaceIdiom: UserInterfaceIdiom {
Expand All @@ -52,15 +51,13 @@ extension EnvironmentValues {

// MARK: -

@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *)
private struct UserInterfaceIdiomEnvironmentKey: EnvironmentKey {

static var defaultValue: UserInterfaceIdiom = .default

}

#if DEBUG
@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *)
private struct RunningSnapshotsEnvironmentKey: EnvironmentKey {

static var defaultValue: Bool = false
Expand Down
1 change: 0 additions & 1 deletion RevenueCatUI/Helpers/ColorInformation+MultiScheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ extension TemplateViewConfiguration {
import SwiftUI

// Helpful acessors
@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *)
extension PaywallData.Configuration.Colors {

var backgroundColor: Color { self.background.underlyingColor }
Expand Down
2 changes: 0 additions & 2 deletions RevenueCatUI/Helpers/ImageLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ protocol URLSessionType {
}

@MainActor
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
final class ImageLoader: ObservableObject {

enum Error: Swift.Error, Equatable {
Expand Down Expand Up @@ -99,7 +98,6 @@ extension URLSession: URLSessionType {}

private extension Data {

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
func toImage() -> ImageLoader.Value {
#if os(macOS)
if let image = NSImage(data: self) {
Expand Down
7 changes: 0 additions & 7 deletions RevenueCatUI/Modifiers/ViewExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import Foundation
import SwiftUI

@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *)
extension View {

@ViewBuilder
Expand Down Expand Up @@ -229,7 +228,6 @@ private struct ScrollableIfNecessaryModifier: ViewModifier {

// MARK: - Size changes

@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *)
extension View {

/// Invokes the given closure whethever the view size changes.
Expand Down Expand Up @@ -287,7 +285,6 @@ extension View {

#if canImport(UIKit)

@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *)
extension View {

@ViewBuilder
Expand Down Expand Up @@ -322,7 +319,6 @@ extension View {

}

@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *)
private struct RoundedCorner: Shape {

var radius: CGFloat
Expand All @@ -341,10 +337,8 @@ private struct RoundedCorner: Shape {

// MARK: - Preference Keys

@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *)
private protocol ViewDimensionPreferenceKey: PreferenceKey where Value == CGFloat {}

@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *)
extension ViewDimensionPreferenceKey {

static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
Expand Down Expand Up @@ -385,7 +379,6 @@ private struct ViewSizePreferenceKey: PreferenceKey {

// MARK: -

@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *)
private extension Axis {

var scrollViewAxis: Axis.Set {
Expand Down
1 change: 0 additions & 1 deletion RevenueCatUI/Purchasing/PurchaseHandler+TestData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ extension PurchaseHandler {

}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
extension Task where Success == Never, Failure == Never {

static func sleep(seconds: TimeInterval) async {
Expand Down
1 change: 0 additions & 1 deletion RevenueCatUI/Templates/Template5View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ private extension Template5View {

}

@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *)
private extension PaywallData.Configuration.Colors {

var featureIcon: Color { self.accent1Color }
Expand Down
1 change: 0 additions & 1 deletion Sources/Attribution/AttributionPoster.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ final class AttributionPoster {
}
}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
var adServicesTokenToPostIfNeeded: String? {
get async {
#if os(tvOS) || os(watchOS)
Expand Down
5 changes: 0 additions & 5 deletions Sources/Diagnostics/FileHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import Foundation

/// A wrapper that allows basic operations on a file, synchronized as an `actor`.
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
protocol FileHandlerType: Sendable {

/// Returns an async sequence for every line in the file
Expand All @@ -32,7 +31,6 @@ protocol FileHandlerType: Sendable {

}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
actor FileHandler: FileHandlerType {

private var fileHandle: FileHandle
Expand Down Expand Up @@ -139,7 +137,6 @@ actor FileHandler: FileHandlerType {

// MARK: - Errors

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
extension FileHandler {

enum Error: Swift.Error {
Expand All @@ -157,7 +154,6 @@ extension FileHandler {

// MARK: - Private

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
private extension FileHandler {

func moveToBeginningOfFile() throws {
Expand Down Expand Up @@ -214,7 +210,6 @@ private extension FileHandler {

}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
private extension FileHandle {

convenience init(_ url: URL) throws {
Expand Down
37 changes: 9 additions & 28 deletions Sources/Error Handling/ErrorUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -355,34 +355,15 @@ enum ErrorUtils {
)
}

if #available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *) {
switch error {
case let purchasesError as PurchasesError:
return purchasesError
// This line crashes on iOS 12.x only (see https://github.com/RevenueCat/purchases-ios/pull/1982).
case let convertible as PurchasesErrorConvertible:
return convertible.asPurchasesError
case let error as PublicError where error.domain == ErrorCode.errorDomain:
return handlePublicError(error)
default:
return createUnknownError()
}
} else {
switch error {
case let purchasesError as PurchasesError:
return purchasesError
// `as PurchasesErrorConvertible` crashes on iOS 12.x, so these explicit casts are a workaround.
// We can't guarantee that these are exhaustive, but at least this covers the most common cases,
// and the `default` below ensures that we don't crash for the rest.
case let backendError as BackendError:
return backendError.asPurchasesError
case let networkError as NetworkError:
return networkError.asPurchasesError
case let error as PublicError where error.domain == ErrorCode.errorDomain:
return handlePublicError(error)
default:
return createUnknownError()
}
switch error {
case let purchasesError as PurchasesError:
return purchasesError
case let convertible as PurchasesErrorConvertible:
return convertible.asPurchasesError
case let error as PublicError where error.domain == ErrorCode.errorDomain:
return handlePublicError(error)
default:
return createUnknownError()
}
}

Expand Down
4 changes: 0 additions & 4 deletions Sources/FoundationExtensions/AsyncExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import Foundation

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
internal enum Async {

/// Invokes an `async throws` method and calls `completion` with the result.
Expand Down Expand Up @@ -127,7 +126,6 @@ internal enum Async {
/// }
/// }
/// ```
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
static func retry<T>(
maximumRetries: Int = 5,
pollInterval: DispatchTimeInterval = .milliseconds(300),
Expand All @@ -152,7 +150,6 @@ internal enum Async {

}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
internal extension AsyncSequence {

/// Returns the elements of the asynchronous sequence.
Expand All @@ -164,7 +161,6 @@ internal extension AsyncSequence {

}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
internal extension AsyncSequence {

func toAsyncStream() -> AsyncStream<Element> {
Expand Down
41 changes: 4 additions & 37 deletions Sources/FoundationExtensions/Data+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,14 @@ extension Data {

/// - Returns: a hash representation of the underlying bytes, using SHA256.
var hashString: String {
if #available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *) {
var sha256 = SHA256()
return self.hashString(with: &sha256)
} else {
return self.hashString(CC_SHA256, length: CC_SHA256_DIGEST_LENGTH)
}
var sha256 = SHA256()
return self.hashString(with: &sha256)
}

/// - Returns: the SHA1 hash of the underlying bytes.
var sha1: Data {
if #available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *) {
var sha1 = Insecure.SHA1()
return self.hash(with: &sha1)
} else {
return Data(self.hash(CC_SHA1, length: CC_SHA1_DIGEST_LENGTH))
}
var sha1 = Insecure.SHA1()
return self.hash(with: &sha1)
}

fileprivate static func hexString(_ iterator: Array<UInt8>.Iterator) -> String {
Expand All @@ -77,7 +69,6 @@ extension Data {

extension Data {

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
static func randomNonce() -> Data {
return Data(ChaChaPoly.Nonce())
}
Expand All @@ -88,7 +79,6 @@ extension Data {

// MARK: - Hashing

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
extension HashFunction {

func toString() -> String {
Expand All @@ -99,38 +89,15 @@ extension HashFunction {

private extension Data {

typealias HashingFunction = (
_ data: UnsafeRawPointer?,
_ len: CC_LONG,
_ md: UnsafeMutablePointer<UInt8>?
) -> UnsafeMutablePointer<UInt8>?

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
func hashString<T: HashFunction>(with digest: inout T) -> String {
digest.update(data: self)
return digest.toString()
}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
func hash<T: HashFunction>(with digest: inout T) -> Data {
digest.update(data: self)

return Data(digest.finalize())
}

func hash(_ hashingFunction: HashingFunction, length: Int32) -> [UInt8] {
return self.withUnsafeBytes { (bytes: UnsafeRawBufferPointer) -> [UInt8] in
var hash = [UInt8](repeating: 0, count: Int(length))
_ = hashingFunction(bytes.baseAddress, CC_LONG(self.count), &hash)
return hash
}
}

func hashString(_ hashingFunction: HashingFunction, length: Int32) -> String {
return Self.hexString(
self.hash(hashingFunction, length: length)
.makeIterator()
)
}

}
1 change: 0 additions & 1 deletion Sources/FoundationExtensions/Operators+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ infix operator ???

/// Equivalent to `??` but allows an `async` default value.
/// See https://github.com/apple/swift-evolution/blob/main/proposals/0296-async-await.md#future-directions
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
func ??? <T>(value: T?, defaultValue: @autoclosure () async throws -> T) async rethrows -> T {
if let value = value {
return value
Expand Down
1 change: 0 additions & 1 deletion Sources/FoundationExtensions/Result+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ extension Result where Success: OptionalType {

}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
extension Result where Failure == Swift.Error {

/// Equivalent to `Result.init(catching:)` but with an `async` closure.
Expand Down
8 changes: 1 addition & 7 deletions Sources/Identity/CustomerInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,7 @@ import Foundation

let allEntitlementsDescription = self.entitlements.all.mapValues { $0.description }

let verificationResult: String

if #available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *) {
verificationResult = self.entitlements.verification.debugDescription
} else {
verificationResult = "unknown"
}
let verificationResult = self.entitlements.verification.debugDescription

return """
<\(String(describing: CustomerInfo.self)):
Expand Down
Loading

0 comments on commit 5aef999

Please sign in to comment.