Question

Having trouble initiating payment UI for monthly subscription

  • 16 April 2022
  • 2 replies
  • 85 views

Badge +1
I am trying to implement a monthly subscription as part of an in-app purchase.
 I am using a combination of xcode/swift and RevenueCat to implement this feature. In implementing the code that runs when the user clicks the purchase button i get the error saying "Fatal error: NSArray element failed to match the Swift Array Element type
Expected Package but found RCPackage". 

Where the code for the purchase button click is highlighted. Code is "guard let package = offerings.all.first?.value.availablePackages.first ".

I am not sure what to do to fix this issue.

 

 


2 replies

Userlevel 5
Badge +9

Sorry for the delay! Are you still seeing this issue? I’m not sure why Xcode is giving you that error. I just tried your code snippet and included a print, and the code ran and printed successfully:

What happens if you use [0] instead of .first? So instead of this:

guard let package = offerings.all.first?.value.availablePackages.first

Try this:

guard let package = offerings.all.first?.value.availablePackages[0]

I tried this on version 4.3.0 of the SDK using Xcode 13.3.1.

Here’s the code snippet I used so you can easily copy and paste to rule out any syntax errors:

Purchases.shared.offerings { offerings, error in
guard let offerings = offerings, error == nil else {
return
}
guard let package = offerings.all.first?.value.availablePackages.first else {
return
}
print(package.identifier)
}

 

 

Badge

You need to remove the revenucat pod file from your code, they have conflicts with   pod 'Purchases' and the  pod Revenucat.

just delete the   pod Revenucat. from code after that it will work. 

 

Reply