<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rob Evans on Medium]]></title>
        <description><![CDATA[Stories by Rob Evans on Medium]]></description>
        <link>https://medium.com/@robert.evansii?source=rss-a4a4c59d74f2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Cg0kKCaU7xquPu0h</url>
            <title>Stories by Rob Evans on Medium</title>
            <link>https://medium.com/@robert.evansii?source=rss-a4a4c59d74f2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 12:11:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@robert.evansii/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Feature Flags in iOS Mobile Development]]></title>
            <link>https://medium.com/@robert.evansii/feature-flags-in-ios-mobile-development-104a68b50e67?source=rss-a4a4c59d74f2------2</link>
            <guid isPermaLink="false">https://medium.com/p/104a68b50e67</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[developer]]></category>
            <dc:creator><![CDATA[Rob Evans]]></dc:creator>
            <pubDate>Sat, 17 Feb 2024 02:30:47 GMT</pubDate>
            <atom:updated>2024-02-17T02:30:47.922Z</atom:updated>
            <content:encoded><![CDATA[<p>In the dynamic landscape of app development, the need to introduce new features or replace existing ones is ever-present. Traditionally, developers might resort to removing or commenting out old code, integrating the new code, submitting the update to the app store, and then awaiting the review process before releasing the changes. However, this approach poses challenges, especially when addressing major breaking bugs that require immediate fixes, relying on the app store’s review timeline.</p><p>Alternatively, there’s a more agile solution: feature flags. These flags allow you to control the visibility and behavior of specific features without the need for extensive code changes or app store submissions. For instance, if you desire a feature to be active only for a specific timeframe, feature flags enable you to implement logic that governs when the feature appears. No need to submit a new build to the app store — it’s a seamless, efficient process.</p><p>In my own experience as an indie developer, I encountered a scenario where I wanted to present a particular view only during a specific time frame upon the app’s launch. Feature flags proved to be an invaluable tool, offering a streamlined and flexible approach to managing such time-sensitive feature implementations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TzWMcy7uICVu52i9" /></figure><h3><strong>What are feature flags</strong></h3><p>In essence, a feature flag, also known as a feature toggle, is typically a value stored on a server, like Firebase, SupaBase, or a hosted JSON on a server. It is linked to a specific feature name and a boolean value. When the mobile application fetches this object, it checks whether the associated feature is enabled or disabled. If it’s enabled, the app will execute a set of functionalities or present a particular feature. This dynamic control allows developers to manage and release features selectively, providing flexibility and control over the application’s behavior.</p><h3>Server side</h3><p>To kickstart the process, it’s essential to establish a repository for storing the features to be fetched into your app. In my particular case, I’ve opted for SupaBase, leveraging its existing integration within my app. This choice eliminates the need for incorporating additional SDKs or introducing new implementations, simplifying the process to a method call to the table I’ve created. The new table called feature_flag and included the following fields</p><pre>* created_at<br>* is_enabled<br>* feature_name<br>* number_users_seen</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vjcJ9g5sP1b_-KQF" /><figcaption>database table example</figcaption></figure><p>You’ll want the `feature_name` to be something that you can easily understand what the feature is for, but you could also include another field for description if you wish.</p><p>The `number_users_seen` is strictly my use case of tracking how many users have seen the feature, but you could also include additional fields based on your creativity and needs.</p><h3>Client side</h3><p>When establishing the client-side model, it’s crucial to design it in a way that aligns seamlessly with your data structure. A well-organized model ensures clarity and consistency throughout your application.</p><p>Additionally, consider incorporating an enum specifically for your feature names. Enumerations provide a structured and type-safe way to represent a set of distinct values, in this case, the various feature names.</p><p>I won’t be going into the advantages of enums here, but you can read more about them <a href="https://docs.swift.org/swift-book/documentation/the-swift-programming-language/enumerations/">docs.swift.org</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*867ws2vo65lZPH92" /><figcaption>Featureflag model example</figcaption></figure><p>Returning to my specific situation, where I aimed to display a view within a specific time frame and ensure it only appeared once, I adopted an approach akin to the one outlined below. I employed UserDefaults (or @AppStorage in SwiftUI) to keep track of whether the user had seen the prompt. Additionally, I utilized a Published variable for my featureFlags data and another Published variable to determine whether the associated sheet should be presented.</p><ol><li>Get my feature flags</li><li>Call shouldSowGiveAwaySheet</li><li>Call updateHasSeenGiveAwayPrompt</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nqvj9XpD4pDcVkAL" /><figcaption>FeatureFlagManager Example</figcaption></figure><p>Within my class I’ll call getFeatureFlags when FeatureFlagManager is initialized and pull down my feature flags from SupaBase. This could be also not be done in the init and getFeatureFlags can be called at the point of entry that you need to use the feature flag.</p><p>At the point I need to determine if my feature flighted sheet needs to be viewed I can call shouldShowGiveAwaySheet,</p><pre>guard let featureIsEanbled = featureFlags.first(where: <br>  { $0.featureName == .giveAwayPrompt })?.isEnabled else <br>    { self.showGiveAwayFeature = false }</pre><p>The guard statement checks if the feature flag for the giveaway prompt is present in the featureFlags array. If it’s not found, it sets showGiveAwayFeature to false and exits the function early.</p><pre>if featureIsEnabled &amp;&amp; !hasSeenGiveAwayPrompt {<br>  self.showGiveAwayFeature = true<br>  self.updateHasSeenGiveAwayPrompt(featureName: .giveAwayPrompt)<br>}</pre><p>This block executes if the feature is enabled, and the user hasn’t seen the giveaway prompt before.</p><p>It sets showGiveAwayFeature to true to indicate that the giveaway sheet should be displayed.</p><p>Additionally, it calls a method updateHasSeenGiveAwayPrompt to update the @AppStorage showGiveAwayFeature marking that they have now seen the giveaway prompt.</p><pre>self.showGiveAwayFeature = false</pre><p>This line is outside the conditional block, meaning it is executed regardless of whether the feature is enabled and the user has seen the giveaway prompt or not. It sets showGiveAwayFeature to false, ensuring it is not shown by default</p><h3>Elegance of enums</h3><p>The elegance of enums shines through in functions like updateHasSeenGiveAwayPrompt. Although not necessary, I find it valuable to illustrate the use of a switch statement. This approach ensures that when a new feature is introduced, developers are prompted to explicitly handle the corresponding case, fostering code completeness and preventing oversight.</p><p>In the dynamic realm of app development, the judicious use of feature flags and enums emerges as a powerful ally, providing developers with a flexible and organized toolkit. We explored how feature flags enable seamless control over feature releases, allowing for dynamic changes without the need for constant code modifications or lengthy app store reviews. The incorporation of enums, as showcased in functions like updateHasSeenGiveAwayPrompt, not only enhances code readability but also instills a best practice — forcing developers to conscientiously handle new feature cases.</p><p>As we navigate the evolving landscape of application development, these practices prove invaluable. They contribute not only to streamlined processes but also to the creation of resilient and adaptable codebases. By leveraging feature flags and enums, developers can build applications that gracefully respond to changing requirements, making for a more efficient, maintainable, and future-proof development experience.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=104a68b50e67" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>