<?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 Lovekesh Bhagat on Medium]]></title>
        <description><![CDATA[Stories by Lovekesh Bhagat on Medium]]></description>
        <link>https://medium.com/@lovekeshbhagat23?source=rss-2f5a53ccea48------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*xrScL_7PlUOBcFz9jALLWA.jpeg</url>
            <title>Stories by Lovekesh Bhagat on Medium</title>
            <link>https://medium.com/@lovekeshbhagat23?source=rss-2f5a53ccea48------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 03:13:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lovekeshbhagat23/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[“inout” Decoded]]></title>
            <link>https://medium.com/@lovekeshbhagat23/inout-decoded-64da10405038?source=rss-2f5a53ccea48------2</link>
            <guid isPermaLink="false">https://medium.com/p/64da10405038</guid>
            <category><![CDATA[in-out-parameters]]></category>
            <category><![CDATA[call-by-value]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[inout]]></category>
            <category><![CDATA[call-by-reference]]></category>
            <dc:creator><![CDATA[Lovekesh Bhagat]]></dc:creator>
            <pubDate>Fri, 04 May 2018 09:48:25 GMT</pubDate>
            <atom:updated>2018-05-04T09:48:25.157Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kqk5MnuPQ_MCRZg3XJl03w.jpeg" /><figcaption>Swift lang</figcaption></figure><p>Most of the iOS developers know that whenever we pass variable in parameter of a function it is passed as value, but what if we want to pass the variable/property as reference, we can use <strong>“inout” </strong>keyword in the parameter before type.</p><pre>func changeValueToReferenceType(testRef:<strong>inout</strong> Int) {<br>}</pre><p>This is the regular answer to this question but what happens behind the scene is it really a call by reference or something else is taking place.</p><p>Let’s do an experiment by printing passed variable.</p><pre>var testReference:Int = 5</pre><pre>func changeTestReferenceValue(testRef:inout Int) {</pre><pre>    testRef = 6</pre><pre>    print(testRef)</pre><pre>    print(self.testReference)</pre><pre>}</pre><p>Let’s call this function in view did load, now if you can predict the value do it.</p><p>Now we should run this to see what happens.Here is the output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RmMvVbbXhCV95yOGJH7CGA.png" /><figcaption>Ohhhh !</figcaption></figure><p>Program crashes, why?</p><p>Here testReference variable is passed using the inout parameter and when we try to access the original variable within the function then the write access given to the function conflicts with the read access due to which app crashes so we can’t access the testReference as long as the function doesn’t return value. So what happens in when we use the inout keyword.</p><p>According to Apple:</p><pre><strong><em>In-out parameters are passed as follows:</em></strong></pre><ol><li><strong><em>When the function is called, the value of the argument is copied.</em></strong></li><li><strong><em>In the body of the function, the copy is modified.</em></strong></li><li><strong><em>When the function returns, the copy’s value is assigned to the original argument.</em></strong></li></ol><p>So call by reference thing is an illusion yes we can say it and instead of call by reference it is <strong><em>copy-in copy-out</em> or <em>call by value result.</em></strong></p><p>It is basically created to give the <strong>call by reference</strong> functionality but in reality it is <strong>call by value result.</strong>So beware using inout variable in multithreaded environment it may not work as desired.</p><p>Here is link for detail info on <a href="https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/MemorySafety.html#//apple_ref/doc/uid/TP40014097-CH46-ID567">memory safety</a>.</p><p><a href="https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Declarations.html#//apple_ref/doc/uid/TP40014097-CH34-ID545">Link to swift inout parameters</a></p><p>Thanks for reading and keep coding.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64da10405038" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iOS Protocols : Hashable]]></title>
            <link>https://medium.com/@lovekeshbhagat23/ios-protocols-hashable-bda9914183c1?source=rss-2f5a53ccea48------2</link>
            <guid isPermaLink="false">https://medium.com/p/bda9914183c1</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[hash-value]]></category>
            <category><![CDATA[hashable]]></category>
            <category><![CDATA[protocol]]></category>
            <dc:creator><![CDATA[Lovekesh Bhagat]]></dc:creator>
            <pubDate>Fri, 27 Apr 2018 18:15:59 GMT</pubDate>
            <atom:updated>2018-04-28T10:19:51.933Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1c41mnW73hD140pZYFL5kg.png" /></figure><p>In the <a href="https://medium.com/@lovekeshbhagat23/ios-protocols-equatable-comparable-b85998fc9194">last</a> article we discussed about the equatable and comparable protocols in this we will look into one more swift protocol i.e. Hashable.</p><h3>Hashable</h3><p>Hashable is a protocol which provides the power to use a custom class’s object as a key in Dictionary or in set, as per <strong>APPLE </strong>definition for hashable:</p><pre>A type that provides an integer hash value.</pre><p>Many inbuilt types provide hash value or i would say they conform to Hashable protocol.These are Strings, integers, floating-point and Boolean values, and even sets.</p><p>NOTE: <strong>When you define an enumeration without associated values, it gains </strong><strong>Hashableconformance automatically.</strong></p><p>If you conform a class with Hashable protocol and the instances of that class are equal i.e. a==b then a.hashvalue == b.hashvalue will also apply but reverse is not true.</p><p>As per apple:</p><p>Hash values are not guaranteed to be equal across different executions of your program. Do not save hash values to use in a future execution.</p><p>Hashable protocol is inherited from the equatable protocol so you need to conform both the protocols.</p><p>Let’s understand things with the help of an example :-</p><p>We will create a swift class named “Student” with rollNumber</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*Ult2wPfIIPBRBvPz0TW8Vw.png" /></figure><p>Now we need to add hashable to it</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*i1t5awxNr8gcXZ0AKOzEzQ.png" /></figure><p>Some error with pop up regarding the hashable and equatable conformance.We will be overriding “==” operator for equatable conformance and providing hashValue, hashValue should be computed property but for experimenting in the example we are using it as stored property.</p><pre>class Student:Hashable {<br>    var hashValue: Int = 0</pre><pre>    static func ==(lhs: Student, rhs: Student) -&gt; Bool {</pre><pre>         if lhs.rollNumber == rhs.rollNumber {</pre><pre>           return true</pre><pre>         }</pre><pre>      return false</pre><pre>   }</pre><pre>   let rollNumber:Int</pre><pre>    init(rollnumber:Int = 0) {</pre><pre>      self.rollNumber = rollnumber</pre><pre>    }</pre><pre>}</pre><p>Now If we create instance of this Student class and use it as hash value lets see the results.</p><pre>let lovekesh:Student = Student(rollnumber:1)</pre><pre>var studentInfo:Dictionary&lt;Student,String&gt; = Dictionary&lt;Student,String&gt;()</pre><p>Here we created instance of Student named “Lovekesh” with hashValue “0&quot; and rollnumber 1 and declared studentInfo dictionary with Student as key.</p><pre>studentInfo[lovekesh] = &quot;10th Standard&quot;<br>print(studentInfo[lovekesh]!)</pre><p>result of this will be “10th Standard” try it yourself, now what if we change the hashValue and add string again</p><pre>studentInfo[lovekesh] = &quot;10th Standard&quot;</pre><pre>lovekesh.hashValue = 1</pre><pre>studentInfo[lovekesh] = &quot;12th Standard&quot;</pre><pre>print(studentInfo[lovekesh]!)</pre><p>Now what will be printed and how many values Dictionary will be having.</p><p>Dictionary will be having only one value i.e. 12th Standard, So it won’t add two values to particular instance even if we change hashValue.So there is only one value corresponding to one key and it uses present hashValue to retrieve value corresponding to a particular instance.</p><h3><strong>Hashable</strong> and <strong>equatable</strong> Protocols are <strong>updated</strong> in <strong>Swift 4.1</strong></h3><p>In swift 4.1 compiler can write implementations of “==” and hashValue for the value type.For example</p><pre>struct Student: Hashable {<br>    let rollNumber: Int<br>}</pre><p>Only this code can serve our purpose for Hashable protocol.This functionality is provided to reduce the boilerplate code, for every good thing there is some price, If we want that compiler should synthesize it own its own we have to follow some rules defined by apple.</p><p>Here <strong>P</strong> can be Hashable or equatable protocol</p><p>For Enum:</p><p>The following rules determine whether P&#39;s requirements can be synthesized for an enum:</p><ul><li>The compiler does not synthesize P&#39;s requirements for an enum with no cases because it is not possible to create instances of such types.</li><li>The compiler synthesizes P&#39;s requirements for an enum with one or more cases if and only if all of the associated values of all of its cases conform to P.</li></ul><p>For Struct:</p><p>The following rules determine whether P&#39;s requirements can be synthesized for a struct:</p><ul><li>The compiler trivially synthesizes P&#39;s requirements for a struct with <em>no</em> stored properties. (All instances of a struct with no stored properties can be considered equal and hash to the same value if the user opts in to this.)</li><li>The compiler synthesizes P&#39;s requirements for a struct with one or more stored properties if and only if all of the types of all of its stored properties conform to P.</li></ul><p>Here is the <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0185-synthesize-equatable-hashable.md"><strong>link</strong></a> to all the info about it</p><p>Thanks for reading, keep reading. We will be coming with more protocols explainations.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bda9914183c1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iOS Protocols : Equatable | Comparable]]></title>
            <link>https://medium.com/@lovekeshbhagat23/ios-protocols-equatable-comparable-b85998fc9194?source=rss-2f5a53ccea48------2</link>
            <guid isPermaLink="false">https://medium.com/p/b85998fc9194</guid>
            <category><![CDATA[comparable]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[iosprotocols]]></category>
            <category><![CDATA[equatable]]></category>
            <dc:creator><![CDATA[Lovekesh Bhagat]]></dc:creator>
            <pubDate>Mon, 19 Feb 2018 18:40:06 GMT</pubDate>
            <atom:updated>2018-02-20T05:15:42.694Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s-P6GJ2NiN6wz9KvI8TfXg.png" /></figure><p>iOS is moving towards a protocol-oriented programming since <a href="https://developer.apple.com/videos/play/wwdc2015/408/">WWDC 2015</a> where apple mentioned about it and since then Apple has introduced different protocols for us to use, which makes our tasks easier and convenient.While working I came across many iOS protocols which can be used for different tasks in this article I am going to discuss two of them with their use. Equitable and Comparable.</p><h3><strong>Equatable</strong></h3><p>Equatable protocol introduced by apple to provide us with the functionality to check the equality between two instances of a class, with the help of equatable protocol we can use “==” and “!=” operators.The class which is needed to be compared should conform this protocol.Below is the example for it.</p><p>Suppose we created a structure, named student</p><pre>struct Student {</pre><pre>   let rollNumber:Int? </pre><pre>   let name:String?</pre><pre>   init(rollNumber:Int,name:String) {</pre><pre>       self.rollNumber = rollNumber</pre><pre>       self.name = name</pre><pre>    }</pre><pre> }</pre><p>and we have created two instances of student</p><pre>let robin:Student = Student(rollNumber:1, name:&quot;Robin&quot;)</pre><pre>let lovekesh:Student = Student(rollNumber:1, name:&quot;Lovekesh&quot;)</pre><p>and we want to compared these two instances</p><pre>if(robin == lovekesh) {<br>    print(&quot;same instances&quot;)<br>}</pre><p>But in this case Xcode will show an error</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*125PMahdnE9CFQPmGLgbQQ.png" /><figcaption>Error message</figcaption></figure><p>So compiler is not understanding what we are doing to resolve this problem we need to inherit and conform <strong>Equatable protocol </strong>and conforming equatable means overriding the “==” operator, below is the example</p><pre>struct Student:Equatable {<br>    <br>     static func ==(lhs: Student, rhs: Student) -&gt; Bool {<br>     <br>     if lhs.rollNumber == rhs.rollNumber {<br>          return true<br>     } else {<br>          return false<br>     } <br>  }</pre><pre>let rollNumber:Int?<br>let name:String?</pre><pre>  init(rollNumber:Int,name:String) {<br>    self.rollNumber = rollNumber<br>    self.name = name<br>  }<br>}</pre><p>Now we can compare the two instances, but important thing is that they should be equatable on the basis of some property and in above example it is done using roll number.Now we can try to equate the two instances.</p><pre>if(robin == lovekesh) {<br>    print(&quot;same roll numbers&quot;)<br>}</pre><p>After conforming equatable protocol we can use “==” and “!=” operators on custom classes objects.</p><h3>Comparable</h3><p>This is an another protocol provided by iOS, which provide us the functionality to use &lt;, &lt;=, &gt;=, and &gt; operators on the custom class objects, it is similar to equatable protocol i.e. we need to conform it and implement it’s methods, one more important thing about comparable protocol is that is it inherited from equatable so it must override “==” operator as well, so we need to override “==” and “&lt;” operators.Below is the example for it.</p><pre>static func &lt;(lhs: Student, rhs: Student) -&gt; Bool {</pre><pre>  if lhs.rollNumber! &lt; rhs.rollNumber!{<br>      return true<br>   } else {<br>      return false<br>   }<br>}</pre><pre>static func ==(lhs: Student, rhs: Student) -&gt; Bool {<br>    if lhs.rollNumber == rhs.rollNumber {<br>         return true<br>       } else {<br>         return false<br>      }<br>   }<br>}</pre><p>Above two methods are necessary to implement in the struct or class where it needs to be conformed, as soon as we implement these methods we can easily compare instances of respective struct or class</p><p>One more interesting fact about comparable protocol, if we create an array of Student which is using comparable protocol, we can use sort function on that array directly without mentioning anything.Below is the example</p><pre>let robin:Student = Student(rollNumber:1, name:&quot;Robin&quot;)</pre><pre>let lovekesh:Student = Student(rollNumber:0, name:&quot;Lovekesh&quot;)</pre><pre>var studentArr:[Student] = [robin,lovekesh]</pre><pre>studentArr.sort()</pre><pre>print(studentArr)</pre><p>In above ways we can use these protocols.Please give it a try.I will be coming up with some more swift protocols soon.Thanks for reading this article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b85998fc9194" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PRODUCT FLAVOURING iOS / Build Configurations iOS]]></title>
            <link>https://medium.com/@lovekeshbhagat23/product-flavouring-ios-build-configurations-ios-8553302cbb4d?source=rss-2f5a53ccea48------2</link>
            <guid isPermaLink="false">https://medium.com/p/8553302cbb4d</guid>
            <category><![CDATA[productflavouring]]></category>
            <category><![CDATA[build-configuration]]></category>
            <category><![CDATA[xcconfig]]></category>
            <category><![CDATA[environment]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Lovekesh Bhagat]]></dc:creator>
            <pubDate>Sun, 23 Jul 2017 14:27:13 GMT</pubDate>
            <atom:updated>2017-08-03T11:20:29.885Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OvrV2t0auAp_Kgp72O4swQ.jpeg" /></figure><p>In iOS we usually face issues related to product flavouring , how we can manage builds for different types of environments (development , production or staging). To manage builds we can use <strong>xcconfig files.</strong></p><p><strong><em>What are xcconfig files ?</em></strong></p><p><em>A build configuration file, also known as an </em><a href="http://help.apple.com/xcode/mac/9.0/#/dev745c5c974"><em>xcconfig</em></a><em> file, is a plain text file that defines and overrides the build settings for a particular build configuration of a project or target.</em></p><p><strong><em>How we can use them to manage builds?</em></strong></p><p>Below is the step by step tutorial to create a awesome system to manage build types.</p><h3>STEP 1:</h3><p>Create a iOS project and add an Configuration folder (or whatever you want to name it) outside your target folder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/207/1*R-2BfcZpkLgHo7qMoYF90g.png" /><figcaption>Create configuration folder</figcaption></figure><p>Add configuration folder to your project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iOjUdfd0Tmbj0ZRWink7Zw.png" /></figure><h3>STEP 2:</h3><p>Add configuration files to your project (to configuration folder).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*0G3Pw1W7-5kWL6A-sAOowA.png" /></figure><p>You can add as many configuration according to your needs we will add two one for development and one for production</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*1gEaVfVPsawnyx39DRlnsQ.png" /></figure><h3>Step 3:</h3><p>Map Configuration files with project configurations</p><p>Select Project -&gt; Info -&gt; Configurations</p><p>Select Debug mode for and you can see DevMode config and ProdMode config , select one of them according to your need , we will select DevMode for debug and ProdMode for Release</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*__t6N5ukSzucixp7Du2gxQ.png" /></figure><h3>STEP 4:</h3><p>Add properties to config files you want to access for different flavour</p><pre>BASEURL = TestDevUrl</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*XKNihIb_yfMf4doBm1r28Q.png" /><figcaption>Dev Mode</figcaption></figure><pre>BASEURL = TestProdUrl</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/1*5kHNtIHBQfQpvR6eD0SdDw.png" /><figcaption>Prod Mode</figcaption></figure><h3>STEP 5:</h3><p>Adding different schemes for different flavours.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*rhz66AKW93Xb7J9fnt-Wpg.png" /><figcaption>Add New Scheme</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*wAYJX1V400IbLmIUh7QbJA.png" /></figure><p>Edit scheme</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/1*v7c_-ptWh4Qv-L-2jFrgOQ.png" /><figcaption>Edit scheme</figcaption></figure><p>After pressing edit scheme you can see a menu to edit present schemes , we will change to new prod scheme , change</p><pre> Run -&gt; Build configuration -&gt; Release</pre><p>Now if you run with prod scheme it will run with</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*L2w58yYZyPNmhLcqELjjNA.png" /></figure><h3>STEP 6:</h3><p>Add corresponding properties to plist</p><p>We will add same properties to plist with the help of which we can access these properties in our code</p><pre>Value: $(BASEURL)</pre><pre>Key: BaseUrl</pre><pre>Type: String</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/1*osg6Aa6-ii1mMI3R44JgWg.png" /></figure><h3>STEP 7:</h3><p>Access value in code using:</p><pre> print(Bundle.main.infoDictionary?[“BaseUrl”] as! String)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*Y5VCds5Dcvl0e-_P9ktFcA.png" /><figcaption>DevMode</figcaption></figure><p>Change the scheme to production and than try it again (do try it on device because in simulator it does work nicely)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/229/1*DUzenuVqrkiB5AGbFMxUeA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*3IxRkPvdRqM-eAASdAgwbg.png" /><figcaption>You will see production url</figcaption></figure><h4>Now you can add properties to config files and easily access on the basis of schemes.</h4><h4><strong>Pods handling</strong></h4><p>In case you are working with pods , so you need to include pods config files as well in the configuration files.</p><p>For both development and production environments.</p><p>You will come across error because the config files for the pods are missing to resolve this problem check your code , you must be having</p><pre>Targets Support Files -&gt; Pods-&lt;#ProjectName#&gt;</pre><p>In the above folder you will be having two config files with some additional files</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*6Y9-c9odgh1LLHDKNZA67w.png" /><figcaption>Pods config files</figcaption></figure><p>Now we can include these files in the corresponding files config files.We need to include relative pod path not absolute path for example</p><pre>#include “Pods/Target Support Files/Pods-&lt;#project name#&gt;/Pods-&lt;#projectname#&gt;.debug.xcconfig”</pre><p>this is for debug</p><pre>#include “Pods/Target Support Files/Pods-&lt;#project name#&gt;/Pods-&lt;#projectname#&gt;.release.xcconfig”</pre><p>this is for release</p><p>it look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*pIqhnatSQKIbIc4yoiCFiw.png" /><figcaption>Debug</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*m7zsocs3HZtelReRNEC_Eg.png" /><figcaption>Release</figcaption></figure><p>Working with URL’s</p><p>If you are working with the URL’s than use $() as escape character. I was trying hard to find out a solid solution for this but not able to find out , will update it as soon as i will found a solution for this.</p><p>Thanks and do write comments for suggestions , reviews or any doubts.I will respond quickly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8553302cbb4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>