<?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 Mutasem on Medium]]></title>
        <description><![CDATA[Stories by Mutasem on Medium]]></description>
        <link>https://medium.com/@mutasem_98750?source=rss-9680f04cfc71------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*fQ1Pwv4dctEvbpHX.jpg</url>
            <title>Stories by Mutasem on Medium</title>
            <link>https://medium.com/@mutasem_98750?source=rss-9680f04cfc71------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 03:36:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mutasem_98750/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[Lazy variable and Computed properties]]></title>
            <link>https://medium.com/@mutasem_98750/lazy-variable-and-computed-properties-5e7030c5acec?source=rss-9680f04cfc71------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e7030c5acec</guid>
            <dc:creator><![CDATA[Mutasem]]></dc:creator>
            <pubDate>Sun, 03 Oct 2021 17:41:55 GMT</pubDate>
            <atom:updated>2021-10-03T17:41:55.497Z</atom:updated>
            <content:encoded><![CDATA[<p>Lazy variable according to its name refers to “just in time” or it puts off work until you need it. In general speaking , Lazy variable can be classified in two usages , The first one seems like computed property and the second one It turns crucial when we have a high computational process cases and we want to save the memory resources for more important issues.</p><p><strong><em>To clarify both usages I will give two examples.</em></strong></p><p>In some cases we don’t know the some properties values during struct or class initializing and became clear during instances initializing, first example will focus on this ordinary usage.</p><p>In this example we have a skeet competition and every player has a personal profile consists of {<strong><em>name , country ,gunBrand and summary</em></strong>}, when I stared initializing the struct I did not know the information of players so I made <strong><em>summary </em></strong>as<strong><em> </em></strong>a<strong><em> </em></strong>lazy variable like below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cda956a483e31940f0f305ce50026e28/href">https://medium.com/media/cda956a483e31940f0f305ce50026e28/href</a></iframe><p>Afterward when the data of players became ready I created instance firstPlayer and secondPlayer With all data of players.This example as you may notice not a big deal but I think the second example make the important contribution of this story.</p><p>In the next example I create a simulation to a hight process function by counting to 3000 and saved values inside array and eventually take the last term .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a9045c27cdf42dea3a89e9ac9872a5c/href">https://medium.com/media/6a9045c27cdf42dea3a89e9ac9872a5c/href</a></iframe><p>Now let us create a property <strong><em>heavyDuty</em></strong> from <strong><em>simulationToHeavyCaluclationProcess</em></strong> type inside <strong>C<em>ompetition</em></strong> Struct as following :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/92323cff94d0aad25bfccf80e89207a1/href">https://medium.com/media/92323cff94d0aad25bfccf80e89207a1/href</a></iframe><p><strong>The important point here</strong> : when ever we initialize an instance from this struct as below :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c50d81f5e39f86e49e99d88793ce6e9c/href">https://medium.com/media/c50d81f5e39f86e49e99d88793ce6e9c/href</a></iframe><p>Even we did not deal with <strong><em>heavyDuty</em></strong> variable it will be called and it iterate 3000 times before <strong><em>new instance</em></strong> initializing is done . this unwanted process consumes our resources for nothing . So now the magic role of lazy variable comes up . let us make our heavyDuty as lazy variable like below :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d2d82533a620ba9866877c98c02686c2/href">https://medium.com/media/d2d82533a620ba9866877c98c02686c2/href</a></iframe><p>Now If we try to initialize an instance from this struct again as below :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c50d81f5e39f86e49e99d88793ce6e9c/href">https://medium.com/media/c50d81f5e39f86e49e99d88793ce6e9c/href</a></iframe><p>As we can notice <strong><em>heavyDuty</em></strong> variable did not be called and we could save 3000 mSecond.</p><p>if we want to call to <strong><em>heavyDuty </em></strong>it is done as usual like below :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e855550156c27bf7e4c0a410779c928a/href">https://medium.com/media/e855550156c27bf7e4c0a410779c928a/href</a></iframe><p>The value of <strong><em>heavyDuty</em></strong> is calculated once and stored in object it self and no need to recalculate if it is recalled again .….</p><p><strong><em>Summary : </em></strong>Computed property runs calculation every time you are access it , where lazy variable is calculated once on demand and is stored in instance and stay waiting new call.</p><p>Note : when we don’ t have a heavy calculation process no need to over use lazy variable because can make some strange behaviour as swift documentation refers as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5C9u8A3cg1itsm0ogLkbkg.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/42a944ff682730dc9298431ec2c591ac/href">https://medium.com/media/42a944ff682730dc9298431ec2c591ac/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e7030c5acec" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>