Files
purchases-ios/Examples/MagicWeatherSwiftUI/Shared/Sources/Helpers/Extensions.swift
T

44 lines
1.1 KiB
Swift
Raw Normal View History

2021-01-29 14:36:54 -05:00
//
// Extensions.swift
// 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 {
var terms: String {
if let intro = self.storeProduct.introductoryDiscount {
2021-01-29 14:36:54 -05:00
if intro.price == 0 {
return "\(intro.subscriptionPeriod.periodTitle) free trial"
2021-01-29 14:36:54 -05:00
} else {
return "\(self.localizedIntroductoryPriceString!) for \(intro.subscriptionPeriod.periodTitle)"
2021-01-29 14:36:54 -05:00
}
} else {
return "Unlocks Premium"
}
}
}
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"
@unknown default: return "Unknown"
2021-01-29 14:36:54 -05: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
}
}