<?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 Guru Lakshmi on Medium]]></title>
        <description><![CDATA[Stories by Guru Lakshmi on Medium]]></description>
        <link>https://medium.com/@rguruonline?source=rss-1c717eb0e0c1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*MRaZU6m4cnIXB6ob.</url>
            <title>Stories by Guru Lakshmi on Medium</title>
            <link>https://medium.com/@rguruonline?source=rss-1c717eb0e0c1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 02:01:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rguruonline/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[SWIFT : Computed Properties and Property Observers]]></title>
            <link>https://medium.com/@rguruonline/swift-computed-properties-and-property-observers-56374675c9e2?source=rss-1c717eb0e0c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/56374675c9e2</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Guru Lakshmi]]></dc:creator>
            <pubDate>Tue, 31 Jan 2017 09:09:04 GMT</pubDate>
            <atom:updated>2017-01-31T09:09:04.597Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>COMPUTED PROPERTY :</strong></h3><p><strong>Computed Properties </strong>compute the value by providing a<strong> getter</strong> and an optional <strong>setter </strong>to retrieve and set other properties and values indirectly rather than storing values directly.</p><p><strong>get { } :</strong> When retrieving the value of a property this block of code will get executed.</p><p><strong>set { } : </strong>When setting the value of a property this part of code will get executed.</p><p><strong>Example :</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/81c37855728eacfd229cd54df3d6f8c8/href">https://medium.com/media/81c37855728eacfd229cd54df3d6f8c8/href</a></iframe><p>In the above code, <strong>setter</strong> is not used to set the value of the property<strong> area</strong> but to set the value of other property<strong> rad</strong> from which the value of <strong>area</strong> is computed.</p><p><strong>Note:</strong> By default <strong>setter</strong> has default parameter name called <strong>newValue</strong>. But we can also specify our own custom parameter name. For example <strong>setter</strong> can be written like this from below example using <strong>shorthand setter declaration.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/065756fdae25286cb16f2cb12300f8f9/href">https://medium.com/media/065756fdae25286cb16f2cb12300f8f9/href</a></iframe><p><strong>Read only Computed property :</strong> Like I have mentioned before a property declared without <strong>set </strong>block can’t have <strong>newValue</strong>. It is a read-only property.</p><p>Computed properties including read only computed properties must be declared as <strong>var</strong> and not as <strong>let</strong> ( Constant ).</p><p><strong>Note :</strong> The <strong>get</strong> keyword can be omitted when set is not used because get is assumed by the swift compiler. For example :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b71fb3a24d364e4fa092450f7becb235/href">https://medium.com/media/b71fb3a24d364e4fa092450f7becb235/href</a></iframe><p>In the above example, <strong>perimeter</strong> property is read only computed property and hence it return the computed value of <strong>perimeter</strong> when it is called.</p><h3><strong>PROPERTY OBSERVERS :</strong></h3><p>Property observer is used to monitor and to respond accordingly whenever the property value is set and even the new property value is same as the old value. It can be added to any <strong>stored properties</strong> and <strong>inherited properties</strong> which is overridden in subclass except lazy properties. Property Observer is not invoked when the value is set in initializer.</p><p>Property observer can define either <strong>willSet </strong>or<strong> didSet</strong> or both on property based on the situation .</p><p><strong>willSet </strong>: It is called just before the value is set. <strong>willSet</strong> uses current property value in the default parameter name <strong>newValue</strong> when no custom parameter name is given.</p><p><strong>didSet </strong>: It is called right after the value is set. <strong>didSet</strong> uses old property value in the default parameter name <strong>oldValue</strong> when no custom parameter name is given.</p><p><strong>Example :</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/16fd2ff631970e51894b1162de6f7e10/href">https://medium.com/media/16fd2ff631970e51894b1162de6f7e10/href</a></iframe><p>In this example whenever the property name is set the property observers will be called. Initially <strong>willSet </strong>block is executed within which the value about to set is used and after which the actual property name is set with the current value. Then <strong>didSet</strong> block will get executed in which <strong>oldValue</strong> is used.</p><p><strong>Notes :</strong> It is possible to change the property value in <strong>didSet</strong> block but when we do so, it will not trigger the property observer. Property observers will be invoked when a property value of superclass is changed in subclass initializer after the superclass initialization is done.</p><p>Would love to hear your comments and thoughts!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56374675c9e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SWIFT : Use of mutating function in Structs]]></title>
            <link>https://medium.com/@rguruonline/swift-use-of-mutating-function-in-structs-6ceb6f95e03?source=rss-1c717eb0e0c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ceb6f95e03</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Guru Lakshmi]]></dc:creator>
            <pubDate>Wed, 25 Jan 2017 06:01:35 GMT</pubDate>
            <atom:updated>2017-01-25T06:15:51.971Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>SWIFT : Use of mutating function in Structs</strong></p><p>Swift programmers developed <strong>Structs </strong>in such a way that properties of it can not be modified within <strong>Struct </strong>methods. For example, Check the code given below :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc7f80cd3e1e3d7f25efc505ef5d886a/href">https://medium.com/media/dc7f80cd3e1e3d7f25efc505ef5d886a/href</a></iframe><p>On executing the above code we get an error because we are trying to assign a new value to the property <strong>population </strong>of the <strong>Struct City. </strong>By default <strong>Structs </strong>properties can’t be mutated inside its own methods. This is how Apple Developers have built it, so that the <strong>Structs </strong>will have a static nature by default.</p><p>How do we solve it? What’s the alternative?</p><p><strong>Mutating Keyword :</strong></p><p>Declaring function as mutating inside <strong>Struct </strong>allows us to alter properties in <strong>Structs</strong>.</p><p>Line No : 5, of the above code changes to like this,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c21d5e35388b7df05ddf2adbd9fff7b3/href">https://medium.com/media/c21d5e35388b7df05ddf2adbd9fff7b3/href</a></iframe><p>Now we can assign the value of the <strong>newpopulation </strong>to property <strong>population </strong>to within the scope of the method.</p><p><strong>Note :</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/83947471bda61b3a03120b95520b1a0f/href">https://medium.com/media/83947471bda61b3a03120b95520b1a0f/href</a></iframe><p>If we use <strong>let </strong>instead of var for <strong>Struct </strong>objects, then we can’t mutate the value of any properties, Also this is the reason why we get an error when we try to invoke <strong>mutating </strong>function using <strong>let </strong>instance. So it is better to use var whenever you are changing value of a property.</p><p>Would love to hear your comments and thoughts…..</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ceb6f95e03" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>