Files
purchases-ios/Sources/Purchasing/PackageType.swift
T
NachoSoto ceac61e4df Offering: Sendable conformance (#1826)
The type is now immutable, so the compiler ensures it's thread-safe.

For [CSDK-379].
Extracted from #1795 to make it easier to review this in isolation.

[CSDK-379]: https://revenuecats.atlassian.net/browse/CSDK-379?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
2022-08-22 16:01:34 -07:00

86 lines
2.5 KiB
Swift

//
// Copyright RevenueCat Inc. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// PackageType.swift
//
// Created by Nacho Soto on 5/26/22.
import Foundation
///
/// Enumeration of all possible ``Package`` types, as configured on the package.
///
/// #### Related Articles
/// - ``Package``
/// - [Displaying Products](https://docs.revenuecat.com/docs/displaying-products)
///
@objc(RCPackageType) public enum PackageType: Int {
/// A package that was defined with an unknown identifier.
case unknown = -2,
/// A package that was defined with a custom identifier.
custom,
/// A package configured with the predefined lifetime identifier.
lifetime,
/// A package configured with the predefined annual identifier.
annual,
/// A package configured with the predefined six month identifier.
sixMonth,
/// A package configured with the predefined three month identifier.
threeMonth,
/// A package configured with the predefined two month identifier.
twoMonth,
/// A package configured with the predefined monthly identifier.
monthly,
/// A package configured with the predefined weekly identifier.
weekly
}
extension PackageType: CaseIterable {}
extension PackageType: Sendable {}
extension PackageType: CustomDebugStringConvertible {
/// A textual description of the type suitable for debugging.
public var debugDescription: String {
let className = String(describing: PackageType.self)
switch self {
case .unknown: return "\(className).unknown"
case .custom: return "\(className).custom"
default: return "\(className).\(self.description ?? "")"
}
}
}
extension PackageType {
var description: String? {
switch self {
case .unknown: return nil
case .custom: return nil
case .lifetime: return "$rc_lifetime"
case .annual: return "$rc_annual"
case .sixMonth: return "$rc_six_month"
case .threeMonth: return "$rc_three_month"
case .twoMonth: return "$rc_two_month"
case .monthly: return "$rc_monthly"
case .weekly: return "$rc_weekly"
}
}
static let typesByDescription: [String: PackageType] = PackageType
.allCases
.filter { $0.description != nil }
.dictionaryWithKeys { $0.description! }
}