Solved

Swift UI - Errors implementing example project

  • 17 November 2021
  • 1 reply
  • 157 views

Badge +5

When attempting to implement the PaywallView of the example SwiftUI project in my own project targeting iOS 15.0 I am receiving 2 errors.

 

Referencing initializer 'init(_:content:)' on 'ForEach' requires that 'Purchases.Package' conform to 'Identifiable'

ForEach(offering?.availablePackages ?? []) { package in
PackageCellView(package: package) { (package) in

/// - Set 'isPurchasing' state to `true`
isPurchasing = true

/// - Purchase a package
Purchases.shared.purchase(package: package) { (transaction, info, error, userCancelled) in

/// - Set 'isPurchasing' state to `false`
isPurchasing = false

/// - If the user didn't cancel and there wasn't an error with the purchase, close the paywall
if !userCancelled, error == nil {
isPresented = false
}
}
}
}

https://github.com/RevenueCat/purchases-ios/blob/c63984004d09f1b131ffdb2b99cfb1c14eaaa76e/Examples/MagicWeatherSwiftUI/Shared/Sources/Views/PaywallView.swift#L35

 

Value of type 'Purchases.Package' has no member 'terms'

Text(package.terms(for: package))

https://github.com/RevenueCat/purchases-ios/blob/c63984004d09f1b131ffdb2b99cfb1c14eaaa76e/Examples/MagicWeatherSwiftUI/Shared/Sources/Views/PaywallView.swift#L90

 

Any thoughts on what I am doing wrong to generate these errors?

icon

Best answer by cody 19 November 2021, 18:01

View original

1 reply

Userlevel 6
Badge +8

Hey @Sam Petherbridge!

It looks like you might be missing an extension file from the sample apps: https://github.com/RevenueCat/purchases-ios/blob/1058fdbf011bf4d040f2a961149bc564b97e63e9/Examples/MagicWeatherSwiftUI/Shared/Sources/Helpers/Extensions.swift#L14

The package terms method as well as the Package conformance to Identifiable is located in that file for the purposes of the sample app.

Let me know if you have any questions!

Reply