<?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 zzmasoud on Medium]]></title>
        <description><![CDATA[Stories by zzmasoud on Medium]]></description>
        <link>https://medium.com/@zzmasoud?source=rss-c715b4400a9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QLGVYAU2O3_y6nd1f-5QbQ.png</url>
            <title>Stories by zzmasoud on Medium</title>
            <link>https://medium.com/@zzmasoud?source=rss-c715b4400a9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 14:24:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zzmasoud/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[Understanding the Hidden Behaviors of SwiftUI Picker]]></title>
            <link>https://medium.com/@zzmasoud/understanding-the-hidden-behaviors-of-swiftui-picker-b50a21aee75c?source=rss-c715b4400a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/b50a21aee75c</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[zzmasoud]]></dc:creator>
            <pubDate>Wed, 23 Jul 2025 02:44:41 GMT</pubDate>
            <atom:updated>2025-07-23T02:45:01.848Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi everyone, today I want to share some tricky points about Picker in SwiftUI and the mindset that has helped me A LOT understand SwiftUI’s behavior and spot potential issues early. I’ll keep this short, so it should take less than 10 minutes of your time.</p><h3>SwiftUI is a Black Box</h3><p>The goal is simple, create this UI using native SwiftUI Picker:</p><figure><img alt="Goal UI" src="https://cdn-images-1.medium.com/max/1024/1*UcB6zRhTdv9NotIm1e7YQQ.png" /></figure><p>I started with what seemed obvious, an image and text should do the job:</p><pre>struct ContentView: View {<br>    enum Option: String, CaseIterable, Identifiable {<br>        case circle, square, triangle<br>        var id: Self { self }<br>    }<br><br>    @State private var selectedOption: Option = .circle<br>    <br>    var body: some View {<br>        Picker(&quot;Picker&quot;, selection: $selectedOption) {<br>            ForEach(Option.allCases) { option in<br>                HStack {<br>                    Image(systemName: option.rawValue)<br>                        .foregroundStyle(.red)<br>                        .font(.system(size: 40, weight: .bold))<br>                    Text(option.rawValue.capitalized)<br>                }<br>            }<br>        }<br>    }<br>}<br><br>#Preview {<br>    ContentView()<br>}</pre><figure><img alt="Unexpected UI" src="https://cdn-images-1.medium.com/max/1024/1*RKuS-7RKqSzpSc2T7aVbbg.png" /><figcaption>The Picker label has a different layout than its options, even though both are created the same way!</figcaption></figure><p>This isn’t what we were expecting. The code clearly shows a leading Image and Text with a custom font, but the result is plain text. It seems SwiftUI is changing our layout under the hood to conform to Apple&#39;s Human Interface Guidelines for this component!</p><blockquote><strong>I’ve said this many times: SwiftUI is a black box. You throw in different inputs, tweak things here and there, and hope for the outcome you want. And just when you think you’ve nailed it, things change. Why? You’ll see soon!</strong></blockquote><p>Let’s try VStack this time. I’m fine with regular text and image. I just need a subtitle under the title:</p><pre>struct ContentView: View {<br>    enum Option: String, CaseIterable, Identifiable {<br>        case circle, square, triangle<br>        var id: Self { self }<br>    }<br><br>    @State private var selectedOption: Option = .circle<br>    <br>    var body: some View {<br>        VStack {<br>            Text(&quot;UI outside of the picker:&quot;)<br>            HStack {<br>                Image(systemName: Option.circle.rawValue)<br>                    .foregroundStyle(.red)<br>                    .font(.system(size: 40, weight: .bold))<br>                VStack {<br>                    Text(Option.circle.rawValue.capitalized)<br>                    Text(Option.circle.rawValue.uppercased())<br>                }<br>                <br>            }<br>            .padding(.bottom)<br><br>            Text(&quot;UI inside the picker:&quot;)<br>            Picker(&quot;Picker&quot;, selection: $selectedOption) {<br>                ForEach(Option.allCases) { option in<br>                    HStack {<br>                        Image(systemName: option.rawValue)<br>                            .foregroundStyle(.red)<br>                            .font(.system(size: 40, weight: .bold))<br>                        VStack {<br>                            Text(option.rawValue.capitalized)<br>                            Text(option.rawValue.uppercased())<br>                        }<br>                        <br>                    }<br>                }<br>            }<br>        }<br>    }<br>}</pre><p>Still no change! The custom layout works perfectly when it’s not wrapped in a picker, but it’s completely ignored for the options within the picker’s menu. It’s hard to explain this to the design team: “No, it’s not possible!”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k2M5Q-FdGXAMkHP38SWYqA.png" /></figure><p>We spent hours trying different layouts and combinations. Then, out of nowhere, one approach finally worked! Explanation? Luck!</p><pre>struct ContentView: View {<br>    enum Option: String, CaseIterable, Identifiable {<br>        case circle, square, triangle<br>        var id: Self { self }<br>    }<br><br>    @State private var selectedOption: Option = .circle<br>    <br>    var body: some View {<br>        Picker(&quot;Picker&quot;, selection: $selectedOption) {<br>            ForEach(Option.allCases) { option in<br>                Button(action: {}) {<br>                    Text(option.rawValue.capitalized)<br>                    Text(option.rawValue.uppercased())<br>                    Image(systemName: option.rawValue)<br>                }<br>                .tag(option)<br>            }<br>        }<br>    }<br>}</pre><p>yeah I know, it’s not even wrapped in a stack, but it’s exactly what we were looking for 😂🤦‍♂️</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UcB6zRhTdv9NotIm1e7YQQ.png" /></figure><h3>Things Change Easily</h3><p>The context in which a Picker (or any other SwiftUI component) is placed can also dramatically alter its appearance and behavior. For example, this is how a standard disabled Picker appears, grayed out and not selectable:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/373/1*EK6J1MCUdNspUmcPy5-UlA.png" /><figcaption>a disabled Picker</figcaption></figure><p>Now, let’s wrap that same Picker in a Form. Magically, its appearance changes. It even looks selectable, though it correctly remains disabled.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0sQG_Lxi7OnLe1V7yM7C7A.png" /><figcaption>The same Picker but in a Form</figcaption></figure><p>Why does this happen? Just a moment ago, it looked completely different.</p><p>This happens because of hidden behavior inside .pickerStyle(.automatic). If you change it to .pickerStyle(.menu), it behaves the same way even in a form.</p><p>I believe this happens because SwiftUI is a multi-platform UI system. The engineers decided this should be the automatic iOS behavior, a picker in a form looks different than when it’s standalone. If you want more restrictive UI behavior, you need to figure it out yourself!</p><blockquote>This is how I deal with SwiftUI: whenever I want to learn about a component, I experiment with it using different layout combinations and modifiers. I know it’s not documented anywhere. I know it’s not straightforward. But this is exactly how SwiftUI works.</blockquote><p>Hope you found this article helpful and that it saves you time when working with SwiftUI.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b50a21aee75c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My authenticator app on the macOS]]></title>
            <link>https://medium.com/@zzmasoud/my-authenticator-app-on-the-macos-a44d2a65208c?source=rss-c715b4400a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/a44d2a65208c</guid>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[google-authenticator]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[zzmasoud]]></dc:creator>
            <pubDate>Sun, 28 Jan 2024 16:45:56 GMT</pubDate>
            <atom:updated>2024-01-28T16:45:56.007Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HavpTCiFrZqYdxFBTVpuag.jpeg" /></figure><p>Well, I thought it would be easy, but It wasn’t. So I’m sharing mine, short and easy!</p><p>Sometimes it’s annoying and not secure to only have your TOTP (Time-based one-time password) generator on your phone, what if you want to have one on your Mac? That’s my journey to use all open-source projects (and not relying on any online simple solutions) to migrate my Google Authenticator codes to macOS:</p><p>1. on your 📱, tap “transfer accounts” and then “export”. Move the QR code images to your 💻.</p><p>2. How to decode the QR code images? We definitely not going to use online tools since there’s critical data inside them!</p><p>2.1. Install ZBar (<a href="https://github.com/mchehab/zbar">https://github.com/mchehab/zbar</a>)</p><p>2.2. run this command:</p><pre>zbarimg IMAGE_NAME.JPG</pre><p>2.3. Another decoded data! something that starts with “otpauth-migration://offline?data=”, what the heck is this? For now, let’s keep it in a text file.</p><p>3. we’re going to use a Python package, Install it from here (<a href="https://github.com/scito/extract_otp_secrets">https://github.com/scito/extract_otp_secrets</a>).</p><p>3.1. It has a broken GUI on macOS that tries to capture an image of the QR code, but we already decoded it, right? So let’s skip the images and use this command directly:</p><pre>./extract_otp_secrets_2.6.1_macos_x86_64 TEXT_FILE.txt</pre><p>4. Now we have the secret keys! The final step will be to use a secure and easy authenticator on the macOS, it’s COTP! (<a href="https://github.com/replydev/cotp">https://github.com/replydev/cotp</a>)</p><p>4.1. Installing it is tricky since the package doesn’t exist in “brew”.</p><p>4.2. First we need to install Cargo (<a href="https://doc.rust-lang.org/cargo/index.html">https://doc.rust-lang.org/cargo/index.html</a>). It’s the Rust package manager, run:</p><pre>curl https://sh.rustup.rs -sSf | sh</pre><p>4.3. Install cotp with cargo:</p><pre>cargo install cotp</pre><p>4.4 And we’re done! feel free to use this command to learn more about your new authenticator app right inside the Terminal “cotp — help”, for adding a key it’s going to be like this:</p><pre>cotp add - issuer ISSUER - label LABEL </pre><p>Now we have a free, open-source, and secure authenticator app with a simple GUI right inside the Terminal!</p><p>more fun? check out the links:</p><p><a href="https://www.reddit.com/r/commandline/comments/10zdnmj/termotp_an_otp_generator_for_your_terminal_with/">https://www.reddit.com/r/commandline/comments/10zdnmj/termotp_an_otp_generator_for_your_terminal_with/</a></p><p><a href="https://qr.blinry.org/">Reading QR codes without a computer!</a></p><p><a href="https://x.com/DanHollick/status/1570040185500626947?s=20">https://x.com/DanHollick/status/1570040185500626947?s=20</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a44d2a65208c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SwiftUI broken chain of modifiers — Neither a bug nor a feature]]></title>
            <link>https://medium.com/@zzmasoud/swiftui-broken-chain-of-modifiers-neither-a-bug-nor-a-feature-057e4699edd1?source=rss-c715b4400a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/057e4699edd1</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[zzmasoud]]></dc:creator>
            <pubDate>Sat, 28 Oct 2023 17:21:06 GMT</pubDate>
            <atom:updated>2023-10-28T18:19:35.319Z</atom:updated>
            <content:encoded><![CDATA[<h3>SwiftUI broken chain of modifiers — Neither a bug nor a feature</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kMVLcZboQNTReGco" /><figcaption>Photo by <a href="https://unsplash.com/@skamenar?utm_source=medium&amp;utm_medium=referral">Steven Kamenar</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I shared a post on LinkedIn last week regarding an “<a href="https://www.linkedin.com/posts/zzmasoud_xcode15-xcode-ios-activity-7121652824249167872-64ZF?utm_source=share&amp;utm_medium=member_desktop"> Unknown Xcode 15 bug when using SwiftUI</a>”. It received a significant number of views, suggesting that many people share my view that it might be a bug. I’ve decided to investigate it further and arrive at a conclusion.</p><p>First of all, I want to correct myself, it’s not a new issue, it’s not related to the release of Xcode 15, and may have been around since the beginning of SwiftUI, but I’ve never come across it before.</p><p>For the sample code, I just used a view from <a href="https://developer.apple.com/tutorials/app-dev-training/getting-started-with-scrumdinger">Apple’s Scrumdinger</a>. You can copy and paste, and follow with me:</p><pre>import SwiftUI<br><br>struct ContentView: View {<br>    var body: some View {<br>        return VStack {<br>            ProgressView(value: 5, total: 15)<br>            HStack {<br>                VStack(alignment: .leading) {<br>                    Text(&quot;Seconds Elapsed&quot;)<br>                        .font(.caption)<br>                    Label(&quot;300&quot;, systemImage: &quot;hourglass.tophalf.fill&quot;)<br>                }<br>                Spacer()<br>                VStack(alignment: .trailing) {<br>                    Text(&quot;Seconds Remaining&quot;)<br>                        .font(.caption)<br>                    Label(&quot;600&quot;, systemImage: &quot;hourglass.bottomhalf.fill&quot;)<br>                }<br>            }<br>            .accessibilityElement(children: .ignore)<br>            .accessibilityLabel(&quot;Time remaining&quot;)<br>            .accessibilityValue(&quot;10 minutes&quot;)<br>            Circle()<br>                .strokeBorder(lineWidth: 10)<br>                .foregroundStyle(.blue)<br>            HStack {<br>                Text(&quot;Speaker 1 of 3&quot;)<br>                Spacer()<br>                Button(action: {}) {<br>                    Image(systemName: &quot;forward.fill&quot;)<br>                        .imageScale(.large)<br>                         tint(Color.black)<br>                }<br>                .accessibilityLabel(&quot;Next speaker&quot;)<br>            }<br>        }<br>        .padding()<br>    }<br>}<br><br>#Preview {<br>    ContentView()<br>}</pre><p>I know, the preview shows nothing! But it supposed to be this one:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*iuhZO60bCtFuflNXhzr0_w.png" /><figcaption>The preview of the sample code (happy path)</figcaption></figure><p>What about building and running the app, does it work? Yes, it builds successfully and runs a blank screen like the preview.<br>Without going forward, can you guess what is wrong? Just look back there, it’s right in the sample, between the lines.</p><p>I intentionally used this sample with nested views to demonstrate how challenging it can be to debug this particular issue when you have a complicated modifier chain in your SwiftUI views.</p><h3>Tiny spicy dot!</h3><p>The problem is at line 33, tint(Color.black) . It’s perfectly fine, except for one missing dot! It can drive you crazy searching for it in your project. The first time I ran into it, I expected Xcode to swoop in like a hero and save the day, but it disappointed me. After all, it’s more like a syntax error, isn’t it?</p><h3><strong>Why not a compiler error?</strong></h3><p>Well, that was the reason I thought I had found a bug in Xcode 15. To answer the question, let’s look at the <a href="https://developer.apple.com/documentation/swiftui/viewmodifier">documentation</a> aboutViewModifier:</p><blockquote>A modifier that you apply to a view or another view modifier, producing a different version of the original value.</blockquote><p>At the end of chaining modifiers, the compiler expects some View, and what do we have in SwiftUI? Composition of nested and complicated views. Let’s check out another fundamental of SwiftUI, ViewBuilder:</p><blockquote>You typically use ViewBuilder as a parameter attribute for child view-producing closure parameters, allowing those closures to provide multiple child views.</blockquote><p>With the above explanation, nothing is wrong with this view:</p><pre>var body: some View {<br>    Text(&quot;A&quot;)<br>        .font(.title) // translated to some view<br>    Text(&quot;B&quot;)<br>        .font(.title2) // translated to some view<br>    Text(&quot;C&quot;)<br>        .font(.title3) // translated to some view<br>}</pre><p>nor this one!</p><pre>var body: some View {<br>    Text(&quot;A&quot;) // translated to some view<br>    font(.title) // translated to some view<br>    Text(&quot;B&quot;)<br>        .font(.title2) // translated to some view<br>    Text(&quot;C&quot;)<br>        .font(.title3) // translated to some view<br>}</pre><p>While it makes sense to the compiler (because all of them translated to views), one of the modifiers incorrectly disconnected from the view’s modifier chain. It doesn’t make sense at all, that’s why nothing is rendered as a result in the preview or when running the app.</p><h3>How to catch the issue</h3><p>Well, the absence of a certain solution underscores the complexities that can arise within a SwiftUI project. This serves as another illustration of the potential challenges, indicating significant room for improvement.</p><p>None of the things I’m about to mention were helpful to me since I was working on a Swift package with no executable target.</p><ol><li>The only thing that might catch your eye in Xcode is the <strong>Debug navigator.</strong> It doesn’t address the issue, but at least it makes you feel something is wrong!</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*w8iOLao9ctiKVfMtz6Tc_g.png" /><figcaption>High usage of CPU/Memory</figcaption></figure><p>2. After realizing there’s something wrong in your SwiftUI code, you may use Instruments to trace .body invocations and other updates. Seems like it gives us a more accurate analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iMv_2mfllnjXbQrPaKCs8A.png" /></figure><p>Thanks for taking the time to read this topic. I hope you found it helpful and that you never encounter this issue. If you have any insights on debugging or preventing this problem, please share your thoughts, and if you enjoyed the topic, don’t forget to give it a (👏).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=057e4699edd1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>