<?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 Heshan yodagama on Medium]]></title>
        <description><![CDATA[Stories by Heshan yodagama on Medium]]></description>
        <link>https://medium.com/@yodagamaheshan?source=rss-5dd0a0bc5379------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*rSzNvq1kjiuaOdSIE4kM7Q.jpeg</url>
            <title>Stories by Heshan yodagama on Medium</title>
            <link>https://medium.com/@yodagamaheshan?source=rss-5dd0a0bc5379------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 19:44:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yodagamaheshan/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[Eye Care: Relax tired eyes]]></title>
            <link>https://yodagamaheshan.medium.com/eye-care-relax-tired-eyes-bb5b8615d037?source=rss-5dd0a0bc5379------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb5b8615d037</guid>
            <dc:creator><![CDATA[Heshan yodagama]]></dc:creator>
            <pubDate>Sat, 29 Apr 2023 13:53:12 GMT</pubDate>
            <atom:updated>2023-04-29T13:53:12.470Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*haYJxyiHm6jAAY3rHxv_VA.jpeg" /><figcaption>Eye care app icon</figcaption></figure><p>Thank you for using EyeCare, the ultimate eye care companion! We’re here to help you with any questions or issues you may have.</p><p>If you have a question about how to use EyeCare, please visit our FAQ section. You may find answers to some of the most commonly asked questions there.</p><p>If you are experiencing technical issues with the app, please contact our support team at codecrafteyecare@gmail.com . Our team is available to assist you with any technical issues you may be experiencing.</p><p>We welcome any feedback or suggestions you may have to improve EyeCare. If you have any ideas or suggestions, please email us . We value your feedback and will do our best to incorporate your suggestions into future updates.</p><p>Thank you for choosing EyeCare to help you maintain optimal vision, reduce eye fatigue, and promote eye health. We hope you enjoy using our app!</p><p>Q: What is EyeCare?</p><p>A: EyeCare is the ultimate eye care companion app designed to help you maintain optimal vision, reduce eye fatigue, and promote eye health. Our app provides a wide range of exercises and health tips to help you take care of your eyes and reduce eye strain caused by hours of screen time.</p><p>Q: How does EyeCare work?</p><p>A: EyeCare provides a variety of exercises and health tips that are designed to help you take care of your eyes. You can choose from a range of exercises that are specifically designed to reduce eye strain and promote eye health. The app also allows you to set reminders and customize your own eye care routine, so you can easily incorporate eye care into your daily routine.</p><p>Q: Is EyeCare free to use?</p><p>A: EyeCare is free to download and use. However, some features may require a subscription to access in the near future. You can choose to upgrade to a premium subscription within the app to access additional features and exercises.</p><p>Q: How often should I use EyeCare?</p><p>A: EyeCare is designed to be used regularly to help you maintain optimal vision and promote eye health. We recommend using the app at least once a day to see the best results.</p><p>Follow us on : <a href="https://www.linkedin.com/company/apple-code-craft/">https://www.linkedin.com/company/apple-code-craft/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb5b8615d037" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimise your SwiftUI for better performance.]]></title>
            <link>https://yodagamaheshan.medium.com/optimise-your-swiftui-for-better-performance-d7dbac7097b7?source=rss-5dd0a0bc5379------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7dbac7097b7</guid>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[swiftui-performance]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[source-of-truth]]></category>
            <dc:creator><![CDATA[Heshan yodagama]]></dc:creator>
            <pubDate>Tue, 16 Feb 2021 02:17:44 GMT</pubDate>
            <atom:updated>2021-02-26T07:39:30.477Z</atom:updated>
            <content:encoded><![CDATA[<h3>Optimize Your SwiftUI for Better Performance.</h3><p>A view has a lifecycle. As the name suggests, it is a cycle 🔁. This cycle continues to happen while our app is running.</p><p>So,If there is expensive blocking in the cycle it will definitely reduce the <strong>performance</strong> of the app.</p><p>It is very important to have a good understanding of this cycle.Because then we can understand where to optimize.</p><p>So let’s first get an understanding of the life cycle of a view.😇</p><h4>lifecycle of a View</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z8YwtS-U626WSZtAOD4HQw@2x.png" /><figcaption>View lifecycle and places to optimize</figcaption></figure><p>To begin with, let’s see what are views and their role in the SwiftUI system.</p><p>Everything we see on the screen is a view. SwiftUI manages the identity and the lifetime of your views. And because a view defines a piece of UI, it should be lightweight and inexpensive.</p><p>But,</p><blockquote>“the lifetime of a view is separate from the lifetime of a struct that defines it. The struct you create that conforms to the View protocol actually has a very short lifetime. SwiftUI uses it to create a rendering, and then it’s gone.”</blockquote><p>We next see how these changes that we see on view happen.</p><p>We get the <strong>new copy</strong> as the source of truth gets changed(mutated). (SwiftUI gets a new copy by calling the body of the view — <strong>not re-creating the view struct itself</strong>. So the subview <strong>struct</strong>s will be <strong>recreated</strong>). As a result, we see view interact with us.</p><p><em>Summary — view get re-created as source of truth changed.</em></p><p>Now we have an idea about the lifecycle of a View. But, How to avoid slow updates⁉️</p><p>Considering two places at the lifecycle (<em>check the above diagram</em>). we can,</p><p>1️⃣ Avoid Slow Update</p><p>2️⃣ Pass expensive Work to Background Queue</p><h3>1️⃣ Avoid Slow Update</h3><p>Update behind the scene is <strong>creating a new copy</strong> of the view itself (calling the body of the view itself). So updates happen as the source of truth gets changed.</p><p><strong>🔴 Since the SwiftUI calls the body of view (</strong>which we define or already built-in <strong>), all the sub-view will be recreated.</strong></p><p>When change happens to any view inside the body. the whole body (all the other subviews) will be re-generated.</p><p>We as developers should be responsible to let SwiftUI get a new copy of the view quickly.</p><p>In order to do that we can,</p><h4>1. Make view initialization cheap</h4><p>Since SwiftUI creates a new copy of the view every time when their source of truth is mutated.</p><h4>2. Make the body a pure function (Do only creating view description)</h4><p>This means that the body should be free of side effects ( we should not change any state inside from the body or do something else). That means you should simply create your view description and return it. No dispatching, no other work inside the body of the view struct. Just create some views and move on.</p><h4>4. Avoid unnecessary heap allocation.</h4><p>Allocating <strong>heap</strong> is expensive than <strong>stack</strong> allocation. If you are not familiar with what the heap and stack are, you can just think of it as a division of the memory (RAM).</p><p>This <strong>is not</strong> about reducing the space the app has to take in the memory. In here simply we need to avoid repeated heap <strong>allocation</strong>.</p><p>Please check my article about<a href="https://yodagamaheshan.medium.com/how-to-avoid-repeated-heap-allocation-in-swiftui-2906fcb22185"> avoiding unnecessary heap allocation</a>.</p><h3>2️⃣ Pass expensive Work to Background Queue</h3><p>There are multiple sources of the events (these cause event to happen)</p><ol><li>User interaction ( <em>ex- tapping a button </em>)</li><li>Publisher firing( <em>ex- Timer, Notification</em> )</li><li>onChange</li><li>onOpenURL</li><li>onContinueUserActivity</li></ol><p>( 3,4,5 are SwiftUI 2.0 and above)</p><p>Each of these takes a closure as an argument and SwiftUI will run the <strong>closure</strong> at the right time.</p><p><strong>🔴 Thing is that ,</strong>SwiftUI will run <strong>these closures</strong> on the main thread.</p><p>So if we are going to do expensive work. we should consider dispatching to a background queue.</p><blockquote><em>🧑🏻‍🚀</em> <em>One more thing</em> — Avoid making assumptions about when and how often body is called. Remember, SwiftUI can be pretty smart sometimes, which means it might not call body in line with your assumptions.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7dbac7097b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to avoid repeated heap allocation in SwiftUI?]]></title>
            <link>https://yodagamaheshan.medium.com/how-to-avoid-repeated-heap-allocation-in-swiftui-2906fcb22185?source=rss-5dd0a0bc5379------2</link>
            <guid isPermaLink="false">https://medium.com/p/2906fcb22185</guid>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[memory-management]]></category>
            <dc:creator><![CDATA[Heshan yodagama]]></dc:creator>
            <pubDate>Tue, 16 Feb 2021 02:07:21 GMT</pubDate>
            <atom:updated>2021-02-16T02:07:21.521Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pcUB6to_BklJXP-hvoP67g.png" /></figure><p>Here we need to get our hands dirty by running and seeing the resualt of given sample codes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*ldPe2OZVk1yaRy59_Ok6xg.gif" /></figure><p>As you can see here when we change the text value, the values of table view cells also get changed automatically which means that the subviews inside the body of a view also get updated ( get a new copy of it/ re-created).</p><p>Then, our Our @ObserableObject also will re-create , and there is a heap allocation for it as well.</p><p>You know heap allocation is <strong>expensive</strong> than stack allocation. So that we need to avoid these repeated heap allocations.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/31fd743ed5ae1c87dfad034ad2db48d9/href">https://medium.com/media/31fd743ed5ae1c87dfad034ad2db48d9/href</a></iframe><p>we can avoid repeated heap allocation by,</p><ol><li>Passing reference to subviews.</li><li>Using @StateObject (SwiftUI 2.0 and above)</li></ol><h4>1️⃣. Passing reference to subviews.</h4><p>Since the body get called when source of truth changed, we can hold the @ObservedObject in super view , so that it will not be destroyed when other source of truth changed.</p><p><a href="https://gist.github.com/yodagamaheshan/6c18908e4eccab0c99d1c3c71ed95960.js">https://gist.github.com/yodagamaheshan/6c18908e4eccab0c99d1c3c71ed95960.js</a></p><h4>2️⃣. Using @StateObject</h4><p>@StateObject is a combination of @State and @ObservedObject.</p><p><a href="https://gist.github.com/yodagamaheshan/4c250d60799adeb0e6bc26ea9e62bb47.js">https://gist.github.com/yodagamaheshan/4c250d60799adeb0e6bc26ea9e62bb47.js</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2906fcb22185" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using the SceneDelegate Methods]]></title>
            <link>https://medium.com/better-programming/using-the-scenedelegate-21631ccaa137?source=rss-5dd0a0bc5379------2</link>
            <guid isPermaLink="false">https://medium.com/p/21631ccaa137</guid>
            <category><![CDATA[iphone]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Heshan yodagama]]></dc:creator>
            <pubDate>Tue, 19 Nov 2019 08:58:24 GMT</pubDate>
            <atom:updated>2019-12-02T12:54:03.215Z</atom:updated>
            <content:encoded><![CDATA[<h4>Learn the 1:1 mapping of the SceneDelegate to the old AppDelegate methods</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nnq_JnzL_KIkEfP9kVNF_w.png" /></figure><p>In iOS 13, if your application adopts the new scene life cycle, UIKit will stop calling the old ApplicationDelegate methods that relate to UI state.</p><p>Instead, we’ll call the new SceneDelegate methods, and it’s pretty simple since there’s a 1-to-1 mapping for most of these.</p><p>But don’t worry — if you want to adopt multiple-windows support on iOS 13, that doesn’t mean you need to drop support for 12 and before.</p><p>If you’re back deploying, you can simply keep both sets of these methods and UIKit will call the correct set at runtime.</p><h3>The Delegate Methods</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/837/1*WPi3N0jRIcj59pejv2mruA@2x.png" /></figure><p>Now, before we dive into the exact delegate methods, there’s one more additional responsibility that the app delegate gets, and that’s the system will now notify your app delegate when a new scene session is being created or an existing scene session is being discarded.</p><p>Here is an overview:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*qUbJeeGWg9X1Mo5f5T9IoQ@2x.png" /></figure><p>It’s important to not use didDisconnect to actually delete any user data or state permanently, as the scene may reconnect and return later.</p><p>It’s also possible one of your users removed one or more UI scenes from the switcher by swiping up while your actual app process was not running. If your process wasn’t running, the system will keep track of the discarded sessions and call this shortly after your application’s next launch.</p><p>Check out my previous article <a href="https://medium.com/@yodagamaheshan/where-does-this-scenedelegate-come-from-fb93ed5cb49d">“Where Does the SceneDelegate Come From?”</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21631ccaa137" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/using-the-scenedelegate-21631ccaa137">Using the SceneDelegate Methods</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Where Does the SceneDelegate Come From?]]></title>
            <link>https://medium.com/better-programming/where-does-this-scenedelegate-come-from-fb93ed5cb49d?source=rss-5dd0a0bc5379------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb93ed5cb49d</guid>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Heshan yodagama]]></dc:creator>
            <pubDate>Mon, 18 Nov 2019 12:18:28 GMT</pubDate>
            <atom:updated>2019-11-22T23:09:42.819Z</atom:updated>
            <content:encoded><![CDATA[<h4>First came the AppDelegate, now comes the SceneDelegate</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GT5V-qlxRMuRN28Q8nuBZg.png" /><figcaption>Roles of AppDelegate (Image by Heshan Yodagama)</figcaption></figure><p>To get started, let’s talk about some of the roles and responsibilities of the AppDelegate in iOS 12 and before. The AppDelegate had two primary roles:</p><ul><li>To notify your application about process-level events. The system would notify your app delegate when your process was launching or was about to terminate.</li><li>To notify your application about state of its UI. Via methods like EnterForeground and willResignActive, the system will let you know your UI state.</li></ul><p>This is totally fine in iOS 12 and before because applications had one process and also just one user interface instance to match it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JjEHCydyr9NvFxUQjtWqcA.png" /><figcaption>AppDelegate in iOS 12 and before</figcaption></figure><p>AppDelegate in iOS 12 probably looks something like this (except maybe not quite this short).</p><p>When you finish launching with options, you do a couple of things.</p><ul><li>You do some one-time, non-UI global setup, like connecting to a database or initializing your data structures.</li><li>You set up your user interface.</li></ul><p>This is totally valid in 12 and before, but iOS 13’s pattern is invalid. Why?</p><p>Because applications in iOS 13 and above just share one process (as in iOS 12) but may have multiple user interface instances or scene sessions (on the iPad, not on iPhones).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pxH8psIM8QRo4i3W3ke0kw.png" /><figcaption>iPad</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wEiYp2ClzTUU-UQMjMULkA.png" /><figcaption>iPad</figcaption></figure><p>That means the responsibility of the AppDelegate needs to change a bit. It’s still responsible for process events and life cycle, but it’s no longer responsible for anything related to your UI lifecycle. Instead, that’ll all be handled by your UISceneDelegate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4cfUNEdg5bGi6eDKWIrFhg.png" /></figure><p>Well, what does that mean for you? Any UI setup or teardown work that you used to do in your AppDelegate now needs to migrate to the corresponding methods in your SceneDelegate. ( iOS 12 i <em>↠</em> OS 13 ) — (Set up the first view controller of your app, called the <em>root view controller, </em>Configure startup components, such as logging and cloud services.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8DZwz1zsJU3nhKMEOIoSBg.png" /></figure><p>Next: “<a href="https://medium.com/@yodagamaheshan/using-the-scenedelegate-21631ccaa137">Using the SceneDelegate</a>.”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb93ed5cb49d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/where-does-this-scenedelegate-come-from-fb93ed5cb49d">Where Does the SceneDelegate Come From?</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MVVM in iOS]]></title>
            <link>https://yodagamaheshan.medium.com/mvvm-in-ios-31f77d741ae5?source=rss-5dd0a0bc5379------2</link>
            <guid isPermaLink="false">https://medium.com/p/31f77d741ae5</guid>
            <category><![CDATA[work]]></category>
            <category><![CDATA[mvvm-ios]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[mvc]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Heshan yodagama]]></dc:creator>
            <pubDate>Tue, 05 Nov 2019 09:50:28 GMT</pubDate>
            <atom:updated>2020-06-10T06:41:24.318Z</atom:updated>
            <content:encoded><![CDATA[<h4>An Introduction to the Model-View-ViewModel Architecture</h4><p>Yeah, I know that you are familiar with MVC. Here I am going to introduce a better architecture for your next and existing iOS application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9t1SVXZvwZINAztMeMfW8A@2x.png" /><figcaption>MVC Architecture (Image by Heshan Yodagama)</figcaption></figure><p>As you already know, <em>Models </em>hold data, <em>views </em>present an interactive interface to the user, and <em>view controllers</em> mediate the interaction between the model and the view.</p><h4>- Weaknesses of MVC</h4><ol><li>It generates massive view controllers — hard to manage.</li><li>Hard to test (manually or unit testing).</li><li>No better place to do networking things.</li></ol><p>Consider for a moment that, although <em>views </em>and <em>view controllers</em> are technically distinct components, they almost always go hand-in-hand together, paired.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mgdZOCRBShqQIrmtbX-2sw@2x.png" /><figcaption>Model and View (Image by Heshan Yodagama)</figcaption></figure><p>As I mentioned earlier, usually view controller’s logic gets massive, but a lot of it is what’s called ‘presentation logic,’ in MVVM terms — things like transforming values from the model into something the viewer can present, like taking an Date and turning it into a formatted String.</p><p>So we can place our presentation logic separately. We’re going to call this the ‘view model’ — it will sit between the view controller and the model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*27aHq0FurOlNZkzJEN1Pgg@2x.png" /><figcaption>MVVM Architecture (Image by Heshan Yodagama)</figcaption></figure><h4>+ Strength of MVVM</h4><ol><li>Compatible with your existing MVC projects.</li><li>It makes your apps more testable.</li><li>Works best with a binding mechanism.</li></ol><p>We could use KVO (Key-Value Observing), like with MVC, but that can quickly become unmanageable. In practice, <strong>using ReactiveCocoa</strong> is a great way to glue all the moving pieces together.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31f77d741ae5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>