Hey @t1esto!
It looks like your function has a return type of `Offering`, but calling getOfferings is an async method, so you won’t be able to return from the closure result. Instead, you’ll need to return the offering as part of a completion handler. Additionally, you’re force unwrapping the `offerings` result, which may result in crashes.
I’d recommend using a method like this instead:
static func availableOfferingWithIdentifier(_ id: String, completion: @escaping (Offering?) -> Void) {
Purchases.shared.getOfferings { offerings, error in
guard let offerings = offerings else {
completion(nil) // Handle the error or pass nil if offerings are unavailable
return
}
if let offerMatchingID = offerings.offering(identifier: id) {
completion(offerMatchingID) // Pass the result using the completion handler
} else {
completion(nil) // Pass nil if no matching offering is found
}
}
}