2021-01-29 14:36:54 -05:00
|
|
|
//
|
|
|
|
|
// Extensions.swift
|
2021-01-29 14:42:07 -05:00
|
|
|
// Magic Weather SwiftUI
|
2021-01-29 14:36:54 -05:00
|
|
|
//
|
|
|
|
|
// Created by Cody Kerns on 1/26/21.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
2021-09-03 14:17:37 -03:00
|
|
|
import RevenueCat
|
2021-10-22 15:59:13 -07:00
|
|
|
import StoreKit
|
2021-01-29 14:36:54 -05:00
|
|
|
|
|
|
|
|
/* Some methods to make displaying subscription terms easier */
|
|
|
|
|
|
2021-10-22 15:59:13 -07:00
|
|
|
extension Package {
|
2023-04-13 06:43:10 -06:00
|
|
|
var terms: String {
|
|
|
|
|
if let intro = self.storeProduct.introductoryDiscount {
|
2021-01-29 14:36:54 -05:00
|
|
|
if intro.price == 0 {
|
2021-12-13 13:21:43 -08:00
|
|
|
return "\(intro.subscriptionPeriod.periodTitle) free trial"
|
2021-01-29 14:36:54 -05:00
|
|
|
} else {
|
2023-04-13 06:43:10 -06:00
|
|
|
return "\(self.localizedIntroductoryPriceString!) for \(intro.subscriptionPeriod.periodTitle)"
|
2021-01-29 14:36:54 -05:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return "Unlocks Premium"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-13 13:21:43 -08:00
|
|
|
extension SubscriptionPeriod {
|
2021-01-29 14:36:54 -05:00
|
|
|
var durationTitle: String {
|
|
|
|
|
switch self.unit {
|
|
|
|
|
case .day: return "day"
|
|
|
|
|
case .week: return "week"
|
|
|
|
|
case .month: return "month"
|
|
|
|
|
case .year: return "year"
|
2021-11-18 09:58:17 -08:00
|
|
|
@unknown default: return "Unknown"
|
2021-01-29 14:36:54 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-13 13:21:43 -08:00
|
|
|
var periodTitle: String {
|
|
|
|
|
let periodString = "\(self.value) \(self.durationTitle)"
|
|
|
|
|
let pluralized = self.value > 1 ? periodString + "s" : periodString
|
2021-01-29 14:36:54 -05:00
|
|
|
return pluralized
|
|
|
|
|
}
|
|
|
|
|
}
|