Skip to main content
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.

 

 

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 e0] 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.availablePackagese0]

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)
}

 

 


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