<?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 Anshuman Dahale on Medium]]></title>
        <description><![CDATA[Stories by Anshuman Dahale on Medium]]></description>
        <link>https://medium.com/@anshuman.dahale?source=rss-2faae397f82c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*EPH7e8o5veSxF-az.</url>
            <title>Stories by Anshuman Dahale on Medium</title>
            <link>https://medium.com/@anshuman.dahale?source=rss-2faae397f82c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 07:05:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anshuman.dahale/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[Access specifiers in Swift]]></title>
            <link>https://medium.com/@anshuman.dahale/access-specifiers-in-swift-740779b8d9da?source=rss-2faae397f82c------2</link>
            <guid isPermaLink="false">https://medium.com/p/740779b8d9da</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[access-control]]></category>
            <dc:creator><![CDATA[Anshuman Dahale]]></dc:creator>
            <pubDate>Thu, 28 Sep 2023 17:41:35 GMT</pubDate>
            <atom:updated>2023-09-28T17:41:35.682Z</atom:updated>
            <content:encoded><![CDATA[<p>Swift offers 5 different types of access specifiers. Starting from the most strict to the most loose specifier here are those</p><p><strong>1.Private</strong>: <br>This is the most strict access level. Any attribute defined with this access level is accessible only inside that particular scope of code. I<br>In the below example the property age will be accessible only within the Person class. If we have to access it from outside we need to write getter-setter methods the property.</p><pre>class Person {<br>    var name: String<br>    private var age: Int<br>    <br>    init(name: String, age: Int) {<br>        self.name = name<br>        self.age = age<br>    }<br>    <br>    func getAge() -&gt; Int {<br>        return age<br>    }<br>    func setAge(age newAge: Int) {<br>        self.age = newAge<br>    }<br>}<br><br>let firstPerson = Person(name: &quot;Alice&quot;, age: 10)<br>firstPerson.getAge()<br>firstPerson.setAge(age: 20)<br>firstPerson.getAge()2.FilePrivate:<br>Any entity defined with this access level is accessible only in that particular file. </pre><p><strong>2.FilePrivate: <br></strong>The scope of Private variable when increased from the container block to the entire file it becomes FilePrivate. The age property on the Person class can now be modified from within the same file but when tried to modify from outside will result in <em>unaccessible</em> compiler error.</p><pre>class Person {<br>    var name: String<br>    fileprivate var age: Int<br>    <br>    init(name: String, age: Int) {<br>        self.name = name<br>        self.age = age<br>    }<br>}<br><br>let firstPerson = Person(name: &quot;Alice&quot;, age: 10)<br>firstPerson.age = 20</pre><p><strong>3.Internal:<br></strong>This is the default access level, hence any entity or attribute when not defined with and access level defaults to <em>Internal</em>. <br>Entities defined with this access level is accessible only inside the module/target. Generally if we define the <em>Person</em> class as internal in our app target, and suppose we have another target for our Watch app. Then <em>Person</em> class won’t be accessible to the Watch target.</p><p><strong>4.Public:<br></strong>Any entity defined with this access level is accessible inside as well as outside the module. This is specifically useful when we want <em>same piece of functionality</em> with multiple targets.</p><p><strong>5.Open:<br></strong>Similar to the <strong><em>Public</em> </strong>entities defined with this access level are accessible outside the module with an additional feature. If this is an class entity then it can now be even subclassed outside the module. This is not possible with classes defined as <strong><em>Public</em></strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=740779b8d9da" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>