Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cannot convert value of type '[any Product]' to expected argument type '[Product]'

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading