<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Barak Ben hur</title>
    <description>The latest articles on DEV Community by Barak Ben hur (@barak_benhur_28e1ea83a69).</description>
    <link>https://dev.to/barak_benhur_28e1ea83a69</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4196287%2F4055d0e7-278f-4c73-9afc-796b2b54acee.png</url>
      <title>DEV Community: Barak Ben hur</title>
      <link>https://dev.to/barak_benhur_28e1ea83a69</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/barak_benhur_28e1ea83a69"/>
    <language>en</language>
    <item>
      <title>Building Reusable Onboarding and Subscription Flows in SwiftUI</title>
      <dc:creator>Barak Ben hur</dc:creator>
      <pubDate>Tue, 20 Oct 2026 13:58:41 +0000</pubDate>
      <link>https://dev.to/barak_benhur_28e1ea83a69/building-reusable-onboarding-and-subscription-flows-in-swiftui-2oo9</link>
      <guid>https://dev.to/barak_benhur_28e1ea83a69/building-reusable-onboarding-and-subscription-flows-in-swiftui-2oo9</guid>
      <description>&lt;p&gt;A subscription-based iOS app usually needs more than a paywall. You also need to introduce the product, explain its value, load plans, handle purchase outcomes, restore access, and keep premium features in sync with StoreKit.&lt;/p&gt;

&lt;p&gt;When those responsibilities are mixed into a single SwiftUI screen, even small changes become difficult. A better approach is to treat &lt;strong&gt;onboarding, purchasing, and entitlement state as separate concerns&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here is a practical way to design that flow.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Keep onboarding independent from subscription state
&lt;/h2&gt;

&lt;p&gt;Onboarding answers: &lt;em&gt;Has the user seen the introduction?&lt;/em&gt; Subscription state answers: &lt;em&gt;Does the user have access to premium features?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;These are different questions. Completing onboarding should not automatically grant premium access, and dismissing a paywall should not force the user through onboarding again.&lt;/p&gt;

&lt;p&gt;For a simple local onboarding flag, SwiftUI's &lt;code&gt;@AppStorage&lt;/code&gt; works well:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;import&lt;/span&gt; &lt;span class="kt"&gt;SwiftUI&lt;/span&gt;

&lt;span class="kd"&gt;struct&lt;/span&gt; &lt;span class="kt"&gt;AppEntryView&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;View&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;@AppStorage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"onboarding.completed"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;completed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;

    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;some&lt;/span&gt; &lt;span class="kt"&gt;View&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;completed&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kt"&gt;MainView&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kt"&gt;OnboardingView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;onFinish&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;completed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here &lt;code&gt;MainView&lt;/code&gt; and &lt;code&gt;OnboardingView&lt;/code&gt; are your app's own views; the snippet illustrates the routing boundary, not a complete sample application.&lt;/p&gt;

&lt;p&gt;For more complex apps, keep the completion policy in a flow coordinator so the rest of the UI does not need to know where the flag is stored.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Model the paywall as UI, not as the source of truth
&lt;/h2&gt;

&lt;p&gt;A paywall should present products and user actions. It should not decide whether a purchase is valid.&lt;/p&gt;

&lt;p&gt;Think of the UI in terms of explicit states:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Loading&lt;/strong&gt; — subscription products are being requested.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ready&lt;/strong&gt; — products and localized prices are available.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Purchasing&lt;/strong&gt; — a request is in progress.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pending&lt;/strong&gt; — StoreKit reports a pending purchase.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error&lt;/strong&gt; — an operation failed, with a clear retry path.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Premium&lt;/strong&gt; — verified entitlements grant access.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keeping these states explicit makes it easier to avoid empty product cards, duplicate purchase taps, and contradictory messages.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Load real localized pricing from StoreKit 2
&lt;/h2&gt;

&lt;p&gt;Don't hard-code a monthly or yearly price into a SwiftUI paywall. The price and currency can vary by storefront.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;import&lt;/span&gt; &lt;span class="kt"&gt;StoreKit&lt;/span&gt;

&lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;loadSubscriptionProducts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;ids&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;throws&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="kt"&gt;Product&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;products&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;for&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ids&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use each product's localized &lt;code&gt;displayPrice&lt;/code&gt; in your UI, and show a proper loading or retry state if the request fails. Your App Store Connect product IDs must match the IDs used in your application.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Separate purchase results from premium access
&lt;/h2&gt;

&lt;p&gt;A completed purchase flow isn't the same as a durable, current entitlement. Subscriptions can expire or be revoked, and transactions can be updated outside the paywall.&lt;/p&gt;

&lt;p&gt;For auto-renewable subscription IDs, the following simplified check reads StoreKit's current verified entitlements:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;import&lt;/span&gt; &lt;span class="kt"&gt;StoreKit&lt;/span&gt;

&lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;hasPremiumAccess&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;productIDs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Set&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Bool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="kt"&gt;Transaction&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;currentEntitlements&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;guard&lt;/span&gt; &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;verified&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;productIDs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;productID&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Transaction.currentEntitlements&lt;/code&gt; is intended to represent access &lt;em&gt;now&lt;/em&gt;. StoreKit excludes refunded and revoked purchases from the sequence. Its subscription behavior also accounts for eligible grace-period states. For apps with multiple tiers, determine the actual access level from the matching verified products rather than returning a single Boolean.&lt;/p&gt;

&lt;p&gt;A production implementation should also observe &lt;code&gt;Transaction.updates&lt;/code&gt;, refresh entitlement state when transactions change, and finish verified transactions after delivering access. You may also need server-side verification or subscription-status APIs depending on your business model.&lt;/p&gt;

&lt;p&gt;Apple's reference: &lt;a href="https://developer.apple.com/documentation/storekit/transaction/currententitlements" rel="noopener noreferrer"&gt;Transaction.currentEntitlements&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Make restoration and failure states visible
&lt;/h2&gt;

&lt;p&gt;Users may reinstall an app or switch devices. Provide a visible &lt;strong&gt;Restore Purchases&lt;/strong&gt; action and make the resulting state understandable, including when no active entitlement is found.&lt;/p&gt;

&lt;p&gt;Remember to handle canceled and pending purchases as distinct outcomes: they shouldn't be presented as successful premium unlocks. Disable or debounce purchase buttons while the same request is running, and give users a path to retry product loading after a network failure.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Treat accessibility and theme configuration as part of the architecture
&lt;/h2&gt;

&lt;p&gt;Onboarding and paywalls are frequently shown on small screens and translated into multiple languages. Plan for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dynamic Type, scrollable layouts, and buttons that remain reachable at larger text sizes.&lt;/li&gt;
&lt;li&gt;VoiceOver labels and values for selected subscription options.&lt;/li&gt;
&lt;li&gt;Right-to-left layout directions, without assuming that copy is automatically translated.&lt;/li&gt;
&lt;li&gt;Light and Dark appearance, semantic colors, and reduced-motion preferences.&lt;/li&gt;
&lt;li&gt;A clear separation between brand colors and purchase logic.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A reusable component is genuinely reusable only when it can adapt to different products without forcing developers to rewrite its internals.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Keep the integration surface small
&lt;/h2&gt;

&lt;p&gt;An SDK becomes harder to adopt when every application needs to understand dozens of internal views and purchase helpers.&lt;/p&gt;

&lt;p&gt;A practical public integration surface might expose a configuration object for onboarding content, StoreKit product IDs, premium benefits, and a visual theme; one flow host to embed in the app; and a small controller for presenting the paywall.&lt;/p&gt;

&lt;p&gt;Internal views can evolve without requiring consuming apps to be rewritten.&lt;/p&gt;

&lt;h2&gt;
  
  
  Putting it together
&lt;/h2&gt;

&lt;p&gt;For a demo of this approach, I built &lt;strong&gt;LaunchFlowUI&lt;/strong&gt;, a commercial Swift Package that combines configurable SwiftUI onboarding, StoreKit 2 subscription paywalls, purchase restoration, entitlement tracking, and visual themes. It targets iOS 17+ and has no third-party dependencies.&lt;/p&gt;

&lt;p&gt;The demo shows LaunchFlowUI integrated into a sample productivity app called Lumen Focus:&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/ARePzk_V1fY" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://youtu.be/ARePzk_V1fY" rel="noopener noreferrer"&gt;Watch the demo on YouTube&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.codester.com/items/72922/launchflowui-swiftui-onboarding-and-storekit-2" rel="noopener noreferrer"&gt;LaunchFlowUI on Codester&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The packaged SDK has been tested with Xcode's local StoreKit purchase and entitlement scenarios. Live Apple Sandbox and production transactions have not yet been independently verified.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What patterns do you use to keep onboarding, purchase state, and entitlement tracking independent in your SwiftUI apps?&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>ios</category>
      <category>swift</category>
      <category>mobile</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
