Cannot convert value of type '(Any) -> Int' to expected argument type 'Int' error

Hello. I offer renewable subscription packages with in-app purchase in the Xcode app. While applying the codes, I got help from your tutorial in this link. https://www.raywenderlich.com/1458378-in-app-purchase-tutorial-auto-renewable-subscriptions
But I encountered 2 different errors while implementing this code.
Error 1: Cannot convert value of type ‘(Any) → Int’ to expected argument type ‘Int’
Error 2: Value of type ‘PurchasesViewController’ has no member ‘Subscriptions’
I’ve included the faulty parts of the code below. How can I fix these errors?

Subscriptions.store.buyProduct(products[index]) { [weak self] success, productId in
guard let self = self else { return }
guard success else {
let alertController = UIAlertController(title: “Failed to purchase product”,
message: “Check logs for details”,
preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: “OK”, style: .default))
self.present(alertController, animated: true, completion: nil)
return
}

     // self.displayRandomQuote()
    }
    
    
    
    
    let alertController = UIAlertController(
      title: "Choose your subscription",
      message: "Which subscription option works best for you",
      preferredStyle: .alert)

    
    alertController.addAction(
      UIAlertAction(title: "Weekly",
                    style: .default,
                    handler: { action in
                      self.Subscriptions(index: 1)})
    )
    
    
    
    alertController.addAction(
      UIAlertAction(title: "Monthly",
                    style: .default,
                    handler: { action in
                      self.Subscriptions(index: 0)})
    )

    alertController.addAction(
      UIAlertAction(title: "Yearly",
                    style: .default,
                    handler: { action in
                      self.Subscriptions(index: 2)})
    )

    present(alertController, animated: true, completion: nil)

    
    Subscriptions.store.requestProducts { [weak self] success, products in
      guard let self = self else { return }
      guard success else {
        let alertController = UIAlertController(title: "Failed to load list of products",
                                                message: "Check logs for details",
                                                preferredStyle: .alert)
        alertController.addAction(UIAlertAction(title: "OK", style: .default))
        self.present(alertController, animated: true, completion: nil)
        return
          
          
      }
      self.products = products!
    }
    if
        Subscriptions.store.isProductPurchased(Subscriptions.weeklyBtnSub)
            ||                Subscriptions.store.isProductPurchased(Subscriptions.monthlyBtnSub)
            ||                Subscriptions.store.isProductPurchased(Subscriptions.yearlyBtnSub)
    {
      //displayRandomQuote()
    } else {
      //displayPurchaseQuotes()
    }
    
}

Welcome @alialtintas,

could you please highlight where exactly your two errors appear. Also try to reduce the code to the bare minimum that is needed to reproduce these two errors. Lastly, it would also help to know how you defined the Subscriptions class.

This topic was automatically closed after 166 days. New replies are no longer allowed.