Skip to content

Instantly share code, notes, and snippets.

View Arrlindii's full-sized avatar

Arlind Aliu Arrlindii

View GitHub Profile
struct PromotionViewControllerStyle {
let contentView: String
}
class EBookPromotionSplitTest: SplitTestProtocol {
typealias ValueType = PromotionViewControllerStyle
static var identifier: String = "ebookPromotionTest"
var value: PromotionViewControllerStyle
required init(group: String) {
self.value =
group == "social" ?
PromotionViewControllerStyle.init(contentView: "\(TwitterView.self)")
class SplitTestingManager {
static func getSplitValue<Value: SplitTestProtocol>(for split: Value.Type) -> Value.ValueType {
let group = UserDefaults.standard.value(forKey: split.self.identifier) as! String
return Value(group: group).value
}
}
protocol SplitTestProtocol {
associatedtype ValueType: Any
static var identifier: String {get}
var value: ValueType {get}
init(group: String)
}
protocol ICouponManager {
func getAtiveCoupon() -> Coupon?
}
class CouponManager: ICouponManager {
//Same Implementation as from above
}
class MockCouponManager: ICouponManager {
func getAtiveCoupon() -> Coupon? {
PaymentManager(couponManager: MockCouponManager())
PaymentManager(couponManager: CouponManager())
init(paymentManager: PaymentManager) {
self.paymentManager = paymentManager
super.init(nibName: nil, bundle: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
paymentManager.loadProductPrice(completion: configureWithPrice)
}
class CouponManager {
func logEvent(_ event: Event) {
//Code for saving the ocurrign event
}
func deleteUsedCoupon(_ coupon: Coupon) {
//Code that erases the coupon after user has redemed it
}
func getAtiveCoupon() -> Coupon? {
class PaymentManager {
private let dataLoader: PaymentDataLoader
private let priceManager: PriceCalculator
private let couponManager: CouponManager
init(dataLoader: PaymentDataLoader, priceManager: PriceCalculator, couponManager: CouponManager) {
self.dataLoader = dataLoader
self.priceManager = priceManager
self.couponManager = couponManager
}
/*
We offer discount if user cancelled the payment half-way through,
and if user canceled our payment screen multiple times
*/
func getPriceDiscountPercentage() -> Double {
if UserDefaults.standard.bool(forKey: "kPaymentCancelledHalfWay") {
return 0.5
}
let timesScreenOpened = UserDefaults.standard.integer(forKey: "knumberOfTimesPaymentScreenOpened")
if timesScreenOpened > 3 {