I am dealing with this func
public func fetchProduct(productIdentifiers: Set<String>, handler: ((_ result: Result<[Product], InAppPurchase.Error>) -> Void)? = nil) {
productProvider.fetch(productIdentifiers: productIdentifiers, requestId: UUID().uuidString) { (result) in
switch result {
case .success(let products):
handler?(.success(products.map({ Internal.Product($0) })))
case .failure(let error):
handler?(.failure(error))
}
}
}
the context is this
let iap = InAppPurchase.default
iap.fetchProduct(productIdentifiers: [productID], handler: { (result) in
switch result {
case .success(let products):
// Use products
runOnProductPurchased?(products) //1
the last line closure is defined like this
typealias handlerPurchased = ([Product])->Void
var runOnProductPurchased: handlerPurchased?
Product is
import Foundation
import StoreKit
struct Product {
private let skProduct: SKProduct
init(_ skProduct: SKProduct) {
self.skProduct = skProduct
}
}
But this line in //1 shows this error
Cannot convert value of type ‘[any Product]’ to expected argument type ‘[Product]’
why? Isn’t products an array of Product?
>Solution :
Product is also a name used in StoreKit: https://developer.apple.com/documentation/storekit/product
Your namespace conflict is leading to the compiler error. I suggest renaming your Product to something unused in StoreKit