Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Update SwiftUI doc to reflect mock products for previews #276

Merged
merged 4 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
@main
struct SampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
struct PaywallView_Previews: PreviewProvider {
private static let product = TestStoreProduct(
localizedTitle: "My Test Product",
price: 4.99,
localizedPriceString: "$4.99",
productIdentifier: "my_test_product",
productType: .autoRenewableSubscription,
localizedDescription: "A product description."
)

private static let offering = Offering(
identifier: Self.offeringIdentifier,
serverDescription: "My default offering.",
metadata: [:],
availablePackages: [
.init(
identifier: "monthly",
packageType: .monthly,
storeProduct: Self.product.toStoreProduct(),
offeringIdentifier: Self.offeringIdentifier
)
]
)

private static let offeringIdentifier = "default_offering"

static var previews: some View {
PaywallContent(offering: Self.offering)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
---
title: SwiftUI App Lifecycle
slug: swiftui-app-lifecycle
excerpt: Initializing the Purchases SDK in SwiftUI
hidden: true
title: Using RevenueCat with SwiftUI
slug: swiftui-helpers
excerpt: Implementing the Purchases SDK in SwiftUI
hidden: false
---
With the next iteration of SwiftUI announced at WWDC 2020, entire apps can be created with just a simple struct conforming to the new `App` protocol, like so:

# Debugging

The Purchases SDK includes a debug overlay that allows developers to see various configuration details while running an app. You can read more about the debug overlay in our [Debugging](https://www.revenuecat.com/docs/debugging#debug-ui) guide.

# SwiftUI Previews
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 👍🏻


SwiftUI Previews allow developers to preview their views directly in Xcode without building and running your app. The Purchases SDK includes convenience types for displaying mock products and offerings to avoid having to build and run your app to test your paywall.

[block:file]
[
Expand All @@ -16,9 +23,11 @@ With the next iteration of SwiftUI announced at WWDC 2020, entire apps can be cr
]
[/block]

Without traditional application delegate methods commonly used to initialize the SDK, it can seem a little confusing as to where the SDK should be initialized.
# SDK Initialization

We recommend following our [guide](https://www.revenuecat.com/docs/configuring-sdk) for more information on configuring the Purchases SDK. However, we detail multiple methods for configuring the SDK in SwiftUI below.

# Option 1: App Init
## Option 1: App Init

For basic initialization without delegate methods, you can implement the App `init` method:

Expand All @@ -32,9 +41,9 @@ For basic initialization without delegate methods, you can implement the App `in
]
[/block]

# Option 2: App Delegate
## Option 2: App Delegate

Another method of initialization is to use the new `@UIApplicationDelegateAdaptor` property wrapper to configure the Purchases SDK. The `@UIApplicationDelegateAdaptor` gives the option of using UIApplicationDelegate methods that are traditionally used in UIKit applications.
Another method of initialization is to use the `@UIApplicationDelegateAdaptor` property wrapper to configure the Purchases SDK. The `@UIApplicationDelegateAdaptor` gives the option of using UIApplicationDelegate methods that are traditionally used in UIKit applications.

### Creating a Delegate

Expand Down Expand Up @@ -66,4 +75,4 @@ As previously mentioned, the new `@UIApplicationDelegateAdaptor` property attach

Build and run the app, and *Purchases* will be initialized on app launch.

For more information on configuring the SDK, check out the [Configuring SDK](https://docs.revenuecat.com/docs/configuring-sdk) guide.
For more information on configuring the SDK, check out the [Configuring SDK](https://docs.revenuecat.com/docs/configuring-sdk) guide.