<?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 Andi Qml on Medium]]></title>
        <description><![CDATA[Stories by Andi Qml on Medium]]></description>
        <link>https://medium.com/@andreas.kuemmel?source=rss-bc619c1909a3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Andi Qml on Medium</title>
            <link>https://medium.com/@andreas.kuemmel?source=rss-bc619c1909a3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 21:15:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@andreas.kuemmel/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[SwiftUI Views And Women: Eight Ways To Tell Her What To Do.]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">Where to place imperative code in a declarative environment. Without anybody complaining.</p><p class="medium-feed-link"><a href="https://medium.com/@andreas.kuemmel/swiftui-views-and-women-5-ways-to-tell-her-what-to-do-927b84a8ecea?source=rss-bc619c1909a3------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@andreas.kuemmel/swiftui-views-and-women-5-ways-to-tell-her-what-to-do-927b84a8ecea?source=rss-bc619c1909a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/927b84a8ecea</guid>
            <category><![CDATA[swiftui-views]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[views]]></category>
            <dc:creator><![CDATA[Andi Qml]]></dc:creator>
            <pubDate>Tue, 30 Dec 2025 07:52:32 GMT</pubDate>
            <atom:updated>2026-01-26T11:46:35.917Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Never struggle with dependencies and publishers in SwiftUI views again by using this simple „one…]]></title>
            <link>https://medium.com/@andreas.kuemmel/swiftui-views-the-phoenix-from-the-nile-dependencies-and-init-states-unleashed-ce1b5daf8147?source=rss-bc619c1909a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce1b5daf8147</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Andi Qml]]></dc:creator>
            <pubDate>Mon, 08 Sep 2025 18:12:01 GMT</pubDate>
            <atom:updated>2025-12-11T07:10:32.086Z</atom:updated>
            <content:encoded><![CDATA[<h3>Never struggle with dependencies and publishers in SwiftUI views again by using this simple „one size fits all“ approach.</h3><p>SwiftUI usually is smooth and straightforward like a falcon diving for dinner. However, when your view depends on complex data models it can sometimes behave more like a fowl: hard to spot and unwilling to lift off. I stumbled upon a simple view concept for handling dependencies and ensuring correct initial state of views swiftly: No need to pass parameters or bindings all the way down through your view hierarchy. It’s sensitive to dynamic updates even from nested publishers. And it’s robust against state loss after destruction and reinitialization. Forget about .onAppear() workarounds. The View State will always be correct. At init() your view will lift off like the Phoenix, the mythical bird that rose from its own ashes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y2lU8_kpGHEzduxlR1pixQ.png" /><figcaption>Dalle definitely grasped the drama of SwiftUI view states.</figcaption></figure><h4>Feeling duck</h4><p>I like using EnvironmentObjects for views because they are a simple and easy way to access your data model. Just add .environmenObject() to your ContentView and any subview can access it. Yet at some point you will encounter problems like:</p><ul><li><strong>Mute Chicks</strong>: Published properties from nested child classes within the model don´t get broadcasted into the environment. Your view won´t update.</li><li><strong>Twitter Party</strong>: All the views with access to the model via the environment will be reevaluated or even reestablished when the model class itself publishes variables. The performance of your View might suffer or worse it´ll end up in Ice Age: it freezes.</li><li><strong>Crushed By the Wheel of Fortune</strong>: Your views will often be thrown away and recreated by SwiftUI’s lifecycle, e.g. when your view is only conditionally shown within an if / else or a switch statement. The State of your view will be deallocated and lost. When it is requested to show up again, it may reincarnate as roasted duck or chicken nuggets.</li></ul><h4>The Question Marks That Make Your View Fly Again.</h4><p>After chatting with Claude, I was surprised that he didn´t come up with the code shown below — he kindly admitted to being surprised too, positively, of course. Claude and I called it “PhoenixFromNilwana“-View alluding to the view rising like the phoenix from the „nil“-ashes when it gets destroyed.</p><p>Let´s see how it´s done:</p><pre>struct PhoenixFromNilwanaView : View <br>{<br>  /// Shows an image of a Phoenix. size<br>  /// is stored and published from a nested<br>  /// subclass in the DataModel<br><br>  @EnvironmentObject var model  : DataModel<br>  @State var updatedFrame       : CGRect? = nil // nil after init()<br> <br>  var body : some View {<br>  <br>    /// updatedFrame is watched by onReceive(). <br>    /// But after init() no onReceive() has happened yet,<br>    /// the updatedFrame is nil, thus fetch the value from the model.<br>    <br>    let rect = updatedFrame ?? model.someChild.frameForPhoenixView <br>  <br>    Image(&quot;Phoenix&quot;)<br>    .frame(width: rect.width, height: rect.height)<br>  <br>    // Listen to the published value<br>    // and update the view´s State<br><br>    .onReceive(model.someChild.$frameForPhoenixView) { newFrame in<br>      self.updatedFrame = newFrame<br>    }<br> }</pre><p>In order to instantiate your DataModel you can use a standard procedure like this:</p><pre><br>/// your DataModel and children conform to Observable object<br>/// and it publishes Changes<br>class ChildModel : ObervableObject {<br>  @Published var frameForPhoenixView  : CGRect <br>  @Published var frameforGodzillaView : CGRect<br>  var someUnpublishedInt : Int<br>  func updateFrames()<br>  …<br>}<br><br>/// create the DataModel (outside the view)<br>@StateObject var dataModel = DataModel()<br><br>/// and when creating your ContentView this passes<br>/// it to ContentView and ALL its SubViews.<br>ContentView.enviromentObject(dataModel)</pre><p>The PhoenixFromNilwana-View will only update when the specifically properties change that it listens to by .onReceive. In this case its frameForPhoenixView. When frameForGodzillaView changes and publishes the PhoenixView won’t even blink.</p><p>With iOS 17 / macOS 14 the @Observable Macro was introduced for classes. All properties of your class will be published, except you explicitly exclude them with @ObservationIgnored. SwiftUI will check the views if they in deed depend on the published property and only update those views that actually read the property. Which makes update cycles also quicker. This approach also works with nested classes. I prefer the Phoenix approach because it´s easier to implement as you don´t need to provide Keys for the environment.</p><h4>The Falcon Is Back</h4><p>Let´s recap: You can easily subscribe to specific @Published properties in your model by .onReceive(), even when they are buried deep within the model. Pass your dataModel object into .environmentObject() of the toplevel view and forget about passing of parameters or bindings to subviews. <br>Your view will only update when the specific property changes, saving you from frozen views. When being reincarnated, it´s the two question marks (??) that catch the initial nil State and make the view fetch the current state from your DataModel. So even when your view gets burnt, it will rise like phoenix from nilwana – including a clean Karma state.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce1b5daf8147" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>