<?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 Rohit Jangid on Medium]]></title>
        <description><![CDATA[Stories by Rohit Jangid on Medium]]></description>
        <link>https://medium.com/@rohitjangid155?source=rss-a9446ba58e05------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ZNUNEnFNirGWaV67uqo4ZA@2x.jpeg</url>
            <title>Stories by Rohit Jangid on Medium</title>
            <link>https://medium.com/@rohitjangid155?source=rss-a9446ba58e05------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 04:28:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rohitjangid155/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[5 Different ways of working with Optionals in Swift.]]></title>
            <link>https://medium.com/@rohitjangid155/5-different-ways-of-working-with-optionals-in-swift-c53b58ad9d8c?source=rss-a9446ba58e05------2</link>
            <guid isPermaLink="false">https://medium.com/p/c53b58ad9d8c</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swift-optionals]]></category>
            <category><![CDATA[swift-programming]]></category>
            <dc:creator><![CDATA[Rohit Jangid]]></dc:creator>
            <pubDate>Sun, 11 Oct 2020 11:35:23 GMT</pubDate>
            <atom:updated>2020-10-11T11:35:23.888Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WTrTeo36q7p7mzH8mAPcww.png" /></figure><p>Swift uses unique syntax called optionals which is quite neat and you will definitely encounter optionals almost everywhere. Wether it is IBOutlet or some function call you often see optionals in the scene. An optional represents two possibilities: Either there is a value and you can unwrap the optional to access that value, or there isn&#39;t a value at all which means it is <em>nil.</em></p><p>Let’s dive deep into it :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Of1h0GAE4Pj_VhqEq7e96A.png" /><figcaption>1. Box variable is of type string</figcaption></figure><p>Alright, we knew that the box is not empty so we unwrapped it safely but what if the box is empty?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hM4f7BcXxHA8OvgsnjLpWg.png" /><figcaption>2. Box variable is of type optionals string</figcaption></figure><p>So to avoid this problem <em>Optionals</em> comes in the picture, And we say to the compiler “hey listen I am not sure about the box it might have books or not so I am making it as optional”. There are some time when you’re not sure about the values (i.e : while fetching data from the internet etc.) this is when optionals come in handy and they’re really amazing.</p><p>Here are some quick 5 different ways of working with optionals.</p><h3>1. Force Unwrapping</h3><p>One of the most easiest way is to use the force unwrap operator (!) but force unwrapping an optional value will crash your program if the value is nil. Let us consider an example of IBOutlet as you can see below we’re unwrapping the UILabel and if it happens to be nil (no label) while running the app it’ll crash but as we’re 100% sure there will be a label and it is connected to the storyboard it’ll not crash.</p><p>Never ever use force unwrap until you’re 100% sure there is a value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*UNsBTd6yhXEcZNN4AviCzg.png" /><figcaption>Force unwrapping the label</figcaption></figure><h3>2. Check for nil value</h3><p>You can check whether or not an optional contains a value by comparing an optionals to nil using if statement and force unwrapping it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Te6-hhhuE5Q7l_POs9cRYg.png" /><figcaption>Checking for nil value and force unwrapping an optionals</figcaption></figure><p>But checking for every value and force unwrap them feels redundant. To avoid this we have another syntax.</p><h3>3. Optional Binding</h3><p>Optionals binding unwraps the optionals and assign it to constant which is a non-optionals type and making it safe to use but if it happens to be nil it’ll not proceed forward and avoid errors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o0DQc8entT_JEwHvbq2NFg.png" /><figcaption>Optional binding the box variable into new constant boxValue which is of type non-optional</figcaption></figure><p>Just like <em>if</em> statement you can use <em>else</em> clause with optional binding if the value of optional type is nil <em>else</em> part will execute.</p><h3>4. Nil Coalescing Operator</h3><p>The nil-coalescing<em> </em>operator unwraps an optional if it contains a value or returns a default value if it is nil.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q2ulPASVwZAJ8AFV03nPLA.png" /><figcaption>Nil coalescing operator with nil and non-nil value</figcaption></figure><p>As you can see above 👆🏼 when box variable is non-nil (i.e : box is not empty) the default value in not evaluated and this is known as short-circuit evaluation. Default value is only evaluated when the box variable is nil.</p><h3>5. Optional Chaining</h3><p>An Optional may have optional properties or methods which you can think as a box within a box. These are called nested optionals.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MdHbFTB3UnA_MjKfCRmmaA.png" /><figcaption>A person with address have the box</figcaption></figure><p>There is one way to access the value of <em>acutalBox</em> by checking an individual’s address to find the box and than checking the actual box. To do this for a given person object you must unwrap the address optional, the box optional and the actual box optional. This can be done by if-let syntax (i.e : Optional binding) but this will require quite a bit of conditional unwrapping 👇🏼</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8B_3T6mk7UUCBZcvLtUZHw.png" /><figcaption>Unwrapping nested optional through optional binding</figcaption></figure><p>But there is a better way to do this. Instead of assigning a name to every optional each property can be conditionally unwrapped using a method called <em>optional chaining</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I3J8xD6UV39Fb7gkgvYWkA.png" /><figcaption>Optional chaining to unwrap the value of actual box</figcaption></figure><p>As you can see 👆🏼 “?” after every optional property this appears automatically as we are chaining optional.</p><blockquote>The entire chain — &gt; person.address?.box?.actualBox</blockquote><p>This chain keeps unwrapping the properties unless it encounter a <em>nil</em> value. A nil value can break the chain at anytime if found and the <em>if-let </em>statement fails. As a result no value is assigned to the constant and the code inside the braces will never execute but if none of the value is <em>nil</em> the constant will have a value and the code inside the braces will execute.</p><blockquote>“Everybody should learn to program a computer, because it teaches you how to think.” - Steve Jobs</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c53b58ad9d8c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 Things to keep in mind while learning programming.]]></title>
            <link>https://medium.com/@rohitjangid155/5-things-to-keep-in-mind-while-learning-programming-4032c92d7d36?source=rss-a9446ba58e05------2</link>
            <guid isPermaLink="false">https://medium.com/p/4032c92d7d36</guid>
            <category><![CDATA[code]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Rohit Jangid]]></dc:creator>
            <pubDate>Tue, 08 Sep 2020 13:05:33 GMT</pubDate>
            <atom:updated>2020-09-08T13:05:33.377Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hFIUZ69_fkxrW_R7" /><figcaption>Photo by <a href="https://unsplash.com/@emilep?utm_source=medium&amp;utm_medium=referral">Emile Perron</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>If you’re here right now than just remember programming is tough and it’s not easy. And I didn’t mean to start with such overwhelming remark but this is <strong>TRUTH</strong> my friend it’s not always sunshine and rainbows. You need to invest your <strong>Time &amp; Effort</strong> to get some good return on investment which is for sure.</p><p><em>This is how I started after few failure and setbacks I had in past while struggling to learn programming.</em></p><h3>1. Getting Started</h3><p>This is where you take your first baby step towards to world of programming. And it’s always important to get started believe me and here you score a point against the one who is still day dreaming about programming thinking of writing some code for Tesla and Google. Select your programming language and this could be whatever you feel good to get started. I started with Swift and here I scored a point by beginning my journey with programming but this is not the end my friend. So now that you’ve started congratulations for making to Top 100 remember there is no place for the one who is still day dreaming for programming. Welcome to the world of programming and writing your first historical line of code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*Yx6noZpAQ3J8MVN9iZc5LQ.png" /></figure><h3>2. Practice</h3><p>This is where everything gets serious after writing your first historical line of code you’re no longer a normal person! You’re a programmer now and you know what a programmer do and how they maintain their title of programming? They write lots of code and by writing code I mean practice. Give yourself some time and practice, work on your logical thinking solve some question online this will help you while working on your project. The idea is to keep going and build a good habit which will last long when you’ll be working somewhere or on some project this will help you to solve some real life problems with code.</p><h3>3. Build Small Projects</h3><p>Now that you’re comfortable with writing some code this is the time to push yourself out of that comfort zone and start building some project right away. Choose few projects and start working on them one after the other. Remember this is going to be tough and challenging but guess what we’re now programmers so challenges and debugging are going to stays with us life long so get used to it. Look for solutions and keep on building your project. <strong>The real learning is here</strong> until you face some challenges or get stuck finding solution and completing the project will give you that <strong>Confidence.</strong></p><h3>4. Start Reading Documentation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rRQqfFYRIrym1zBj" /><figcaption>Photo by <a href="https://unsplash.com/@sharonmccutcheon?utm_source=medium&amp;utm_medium=referral">Sharon McCutcheon</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>While working on projects and getting stuck is the common thing but to overcome that is super power and the best thing to practice is reading documentation and reading always help. This is not easy even I struggle to understand what that documentation is trying to say but it’s always worth in the end. If it’s still not making sense to you anymore than we obviously have some resource to get a quick look into the problem, Yes you’re correct Lord Google and Lord Stack overflow try to understand atleast before implementing. Once you get used to reading this will help you in writing code and reading errors if any (Only when the fortune favours you). This will ultimately help you in the next point 👇🏼.</p><h3><strong>5. Have Patience</strong></h3><p>Still here? Amazing you’re really doing great this is why patience is important. Building projects or working on something will definitely require patience you need to score that extra point for yourself and your really getting close to what you desired to be. The only thing is <strong>Don’t Quit!</strong> You came so far and you’re definitely close to your goals and giving up now is not at all a good idea. The moment you start struggling<strong> Cheers!</strong> you’re going to learn something new and there is no shortcut to programming. The only best thing about programming is keep learning and keep growing.</p><p>We only see an expert programmers/developer and their successful stories but we’re not aware of the hardwork they put in (behind the scene).</p><blockquote>“The master has failed more times than the beginner has even tried.” <br>― <strong>Stephen McCranie</strong></blockquote><p>All the best for your amazing journey 💪🏼!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4032c92d7d36" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>