Skip to main content
Solved

Swift UI - Errors implementing example project

  • 17 November 2021
  • 1 reply
  • 184 views

Forum|alt.badge.img+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?

Best answer by cody

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!

View original
Did this post help you find an answer to your question?

cody
RevenueCat Staff
Forum|alt.badge.img+8
  • RevenueCat Staff
  • November 19, 2021

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings