mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-10 22:45:55 +05:45
45 lines
1.1 KiB
Swift
45 lines
1.1 KiB
Swift
//
|
|
// Extensions.swift
|
|
// Magic Weather SwiftUI
|
|
//
|
|
// Created by Cody Kerns on 1/26/21.
|
|
//
|
|
|
|
import Foundation
|
|
import RevenueCat
|
|
import StoreKit
|
|
|
|
/* Some methods to make displaying subscription terms easier */
|
|
|
|
extension Package {
|
|
func terms(for package: Package) -> String {
|
|
if let intro = package.storeProduct.introductoryDiscount {
|
|
if intro.price == 0 {
|
|
return "\(intro.subscriptionPeriod.periodTitle) free trial"
|
|
} else {
|
|
return "\(package.localizedIntroductoryPriceString!) for \(intro.subscriptionPeriod.periodTitle)"
|
|
}
|
|
} else {
|
|
return "Unlocks Premium"
|
|
}
|
|
}
|
|
}
|
|
|
|
extension SubscriptionPeriod {
|
|
var durationTitle: String {
|
|
switch self.unit {
|
|
case .day: return "day"
|
|
case .week: return "week"
|
|
case .month: return "month"
|
|
case .year: return "year"
|
|
@unknown default: return "Unknown"
|
|
}
|
|
}
|
|
|
|
var periodTitle: String {
|
|
let periodString = "\(self.value) \(self.durationTitle)"
|
|
let pluralized = self.value > 1 ? periodString + "s" : periodString
|
|
return pluralized
|
|
}
|
|
}
|