What would be the best way to wrap Purchases.shared.purchaserInfo
to just return true
or false
when doing multiple comparisons in an If
statement.
What I want to be able to do is to quickly check if the user has access to PRO features by having a method or a property that return true or false since I need to make multiple checks in an if statement, something like... if userHasAccess && someOtherCheck { // do something}
Is this a valid solution?
Singleton Class:
class IAPHelper {
static let shared = IAPHelper()
func hasAccessToProFeatures()->Bool{
var hasAccess:Bool?
Purchases.shared.purchaserInfo { (purchaserInfo, error) in
if let purchaserInfo = purchaserInfo {
if purchaserInfo.activeEntitlements.contains("myEntitlement") {
hasAccess = true
}else{
hasAccess = false
}
}
}
return hasAccess!
}
}
Usage:
if IAPHelper.shared.hasAccessToProFeatures() && someOtherCheck{
// unlock PRO features
}