<?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 UdayKiran M on Medium]]></title>
        <description><![CDATA[Stories by UdayKiran M on Medium]]></description>
        <link>https://medium.com/@udaykiran.munaga?source=rss-bf8349f9696c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*FpJ3r0BPTaF83Cclq9HrRg.jpeg</url>
            <title>Stories by UdayKiran M on Medium</title>
            <link>https://medium.com/@udaykiran.munaga?source=rss-bf8349f9696c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 23:59:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@udaykiran.munaga/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 Check for internet connectivity]]></title>
            <link>https://medium.com/@udaykiran.munaga/swift-check-for-internet-connectivity-14e355fa10c5?source=rss-bf8349f9696c------2</link>
            <guid isPermaLink="false">https://medium.com/p/14e355fa10c5</guid>
            <category><![CDATA[internet]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[reachability]]></category>
            <category><![CDATA[network-monitor]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[UdayKiran M]]></dc:creator>
            <pubDate>Thu, 16 Jul 2020 10:57:19 GMT</pubDate>
            <atom:updated>2020-07-16T10:57:19.939Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*bFn5YcYVsjAXylGOlXe4DQ.png" /></figure><p>Apple’s <strong>Network</strong> <strong>framework</strong> offers a new API called the <strong>NWPathMonitor</strong> specifically designed to monitor network accessibility.</p><p><strong>NWPathMonitor</strong>: A simple class that notifies the app when there is a change in the network reachability. (Available from iOS 12.0+)</p><p>So this can be very useful if you want to update your UI to let the user know, or if your app wants to perform some actions if there is any network change.</p><p>So, Let’s start</p><ol><li>First step: import Network framework</li></ol><pre>import <strong>Network</strong></pre><p>2. Second step: Create an instance of NWPathMonitor</p><pre>let monitor = NWPathMonitor()</pre><p>3. Third step: Implement closure that gets called whenever network changes</p><pre>monitor.pathUpdateHandler = { path in<br>   if path.status == .satisfied {<br>      print(&quot;Connected&quot;)<br>   } else {<br>      print(&quot;Disconnected&quot;)<br>   }<br>   print(path.isExpensive)<br>}</pre><p>There are two variables to learn about</p><ol><li>.<strong>status</strong>: Indicates the connection is currently available or not</li><li>.<strong>isExpensive</strong>: Boolean value that returns true, if the current connection is over cellular or hotspot.</li></ol><p>4. Fourth Step: Start monitoring</p><pre>let queue = DispatchQueue(label: “Monitor”)<br>monitor.start(queue: queue)</pre><p>5. Fifth Step: Stop Monitoring</p><pre>monitor.cancel()</pre><h3>Initialize monitor for a specific interface type</h3><p>You can create a monitor instance even for a specific interface type(wifi, cellular, or other). NWPathMonitor has an initializer for this purpose. So the monitor only watch that specific interface type</p><pre>public init(requiredInterfaceType: NWInterface.InterfaceType)</pre><p>Below is the class that I used in my project to monitor the network. I required to know two things in my project to do a few operations</p><ol><li>Detect if connected via Cellular network, so that I can avoid some heavy operations.</li><li>Detect if a network is reachable or not, to make API calls, update UI, and post notifications.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12d30b1fc06dac9b83b2a7291ffba9cb/href">https://medium.com/media/12d30b1fc06dac9b83b2a7291ffba9cb/href</a></iframe><p>If you have any comments, questions, or recommendations, feel free to comment!. Also, connect with me on <a href="https://www.linkedin.com/in/uday-kiran-b9b481157/"><strong><em>LinkedIn</em></strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14e355fa10c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[String interpolation in Swift 5]]></title>
            <link>https://medium.com/@udaykiran.munaga/string-interpolation-in-swift-5-eb7e0d3b01c0?source=rss-bf8349f9696c------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb7e0d3b01c0</guid>
            <category><![CDATA[swift-5]]></category>
            <category><![CDATA[string]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[string-interpolation]]></category>
            <dc:creator><![CDATA[UdayKiran M]]></dc:creator>
            <pubDate>Wed, 31 Jul 2019 08:17:56 GMT</pubDate>
            <atom:updated>2019-08-01T06:28:42.279Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-pZHgU-sFMKuzcseAAt8-w.jpeg" /></figure><p>Today, I want to talk about one of the most exciting new features in Swift 5: StringInterpolation (<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0228-fix-expressiblebystringinterpolation.md">SE-0228</a>). Even though it is not completely new but redesigned to open a lot of possibilities.</p><blockquote>The new string interpolation system gives us control to choose how objects should appear in strings.</blockquote><p><strong>The Basics<br></strong>We are used for basic string interpolation like this</p><pre>let count = 3<br>print(“I have \(count) bikes”)<br>//prints “I have 3 bikes”</pre><p>If I want that statement to be printed as “I have three bikes”.Then how would you do that?<br>In Swift 5.0 you can customize that format by extending String.StringInterpolation to provide your custom implementation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/65d2a644dff80feae9db9b48a1d0d973/href">https://medium.com/media/65d2a644dff80feae9db9b48a1d0d973/href</a></iframe><p>We have extended <em>StringInterpolation</em> with a method “<em>appendInterpolation”</em> which has a “<em>stringFormat”</em> parameter</p><p>appendInterpolation methods can specify any parameter signature they wish. The method <strong>appendInterpolation</strong> can accept multiple parameters (with or without default values), can require a label on any parameter (including the first one), and can have variadic parameters. appendInterpolation methods can also throw; if one does, the string literal must be covered by a try, try? or try! keyword</p><p>Now you can use this as below</p><pre>print(“I have \(stringformat: count) bikes”)<br>// This will print as “I have three bikes”</pre><p>I hope you got some understanding of interpolation. But I know you are thinking of how you can use it in your codebase. No worries, We will take one more example. If we had a struct like this,</p><pre>struct <strong>Employee</strong> {<br>      var type: String<br>      var action: String<br>}</pre><pre>let employee1 = <strong>Employee</strong>(type: &quot;Developer&quot;, action: &quot;develop Apps&quot;)<br>print(employee1)</pre><p>This will be printed as <strong>Employee(type: “Developer”, action: “develop Apps”)</strong></p><p>But I want to get my struct as a string like “I am Developer and I develop apps”. We would add an extension to String.StringInterpolation with the method appendInterpolation() which takes “<strong>Employee” </strong>as a parameter.</p><pre>extension String.StringInterpolation {<br>    mutating func appendInterpolation(_ employee: Employee) {<br>        appendLiteral(&quot;I am a \(employee.type) and I will \<br>                                           (employee.action)&quot;)<br>      }<br>}</pre><p>Now we can create an <strong>Employee</strong> and print out their data:</p><pre>let employee1 = <strong>Employee</strong>(type: “Developer”, action: “develop Apps”)<br>let employee2 = <strong>Employee</strong>(type: “Tester”, action: “test Apps”)</pre><pre>print(&quot;\(employee1)&quot;)<br>//prints  “I am Developer and I develop apps”</pre><pre>print(&quot;\(employee2)&quot;)<br>//prints &quot;I am tester and I test apps&quot;</pre><p>Your custom interpolation method can take as many parameters as you need, labeled or unlabeled.</p><p>Till now I had shown you how to extend DefaultStringInterpolation.<br> If you don’t want to use DefaultStringInterpolation, you can define custom string interpolation behavior on a custom type that conforms to ExpressibleByStringInterpolation.</p><p>You can follow me on <a href="https://medium.com/@udaykiran.munaga"><strong><em>Medium</em></strong></a> for fresh articles. Also, connect with me on <a href="https://www.linkedin.com/in/uday-kiran-b9b481157/"><strong><em>LinkedIn</em></strong></a>.<br>If you have any comments, questions, or recommendations, feel free to post them in the comment section below!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb7e0d3b01c0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Is @Unknown attribute really useful?]]></title>
            <link>https://medium.com/@udaykiran.munaga/is-unknown-attribute-really-useful-84c4672e770a?source=rss-bf8349f9696c------2</link>
            <guid isPermaLink="false">https://medium.com/p/84c4672e770a</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[switch]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift-5]]></category>
            <dc:creator><![CDATA[UdayKiran M]]></dc:creator>
            <pubDate>Tue, 30 Jul 2019 20:09:23 GMT</pubDate>
            <atom:updated>2019-07-31T06:22:33.686Z</atom:updated>
            <content:encoded><![CDATA[<p>At first, I am really confused when I studied about @Unknown attribute like: Is it really useful? when to use it? Are there any drawbacks to using it? So I am just writing this blog for anyone who has the same questions.</p><p>Assume you are using a third-party library that had an enum called “HTTPResponseError”.</p><pre>public enum HTTPResponseError: Error {<br> case badRequest<br> case unauthorized<br> case forbidden<br> case notFound<br>}</pre><p>To deal with enums we use Switch statements</p><pre>func printError(error: HTTPResponseError) {<br> switch error {<br> case .badRequest  : print(&quot;badRequest&quot;)<br> case .unauthorized: print(&quot;unauthorized&quot;)<br> case .forbidden   : print(&quot;forbidden&quot;)<br> case .notFound    : print(&quot;notFound&quot;)<br> default           : print(&quot;Unknown error&quot;)<br> }<br>}</pre><p>In swift, every switch statement must be exhaustive. It means you have to implement all the cases. If you don’t want to implement a few cases you will just add default which says “Hey! For any case which I didn’t implement just use the default implementation”.</p><p>Think a situation where the framework updated their enum with a new case serverError. Now if I call printError(.serverError) , it still prints Unknown Error.</p><blockquote>The main drawback when you provide the default is if the enum is updated you never hear about that change.<br>In another way, if you implement all the cases and didn’t provide any default then your code breaks whenever the enum is updated.</blockquote><p>Here comes the @unknown default attribute to the rescue. This can be used only on the default case. Now if a framework adds a new case in the future you’ll be warned about it, but it won’t break your source code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZI4i5SWqLKxbLedkrOt9lQ.png" /><figcaption>Compiler warning on updating the enum</figcaption></figure><blockquote>@unknown default will work the same as default with the additional benefit of warning you on the future enum updates.</blockquote><p>When to use @unknown default?<br>1. If you correctly understand @unknown attribute it helps you when you have handled all cases and you like to know whenever the enum is updated. As I showed in the above example, I would like to hear if any new cases added toHTTPResponseError as it helps me to get a more specific reason for the failure.</p><p>2. It won’t be useful when you handled only a few cases and for the rest, you provided a default implementation. In this case, as all cases are not handled it just throws that warning.</p><p>3. Not useful for the frozen enums and the enums which have no scope to update. For example, take an enum which has two cases True and false. So there is no chance to update them. There is no harm in using @unknown default here at the same time you don’t get any benefit.</p><p>You can follow me on <a href="https://medium.com/@udaykiran.munaga"><strong><em>Medium</em></strong></a> for fresh articles. Also, connect with me on <a href="https://www.linkedin.com/in/uday-kiran-b9b481157/"><strong><em>LinkedIn</em></strong></a>.<br>If you have any comments, questions, or recommendations, feel free to post them in the comment section below!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84c4672e770a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What’s exactly viewDidLayoutSubviews?]]></title>
            <link>https://medium.com/@udaykiran.munaga/whats-exactly-viewdidlayoutsubviews-46cf5a791f49?source=rss-bf8349f9696c------2</link>
            <guid isPermaLink="false">https://medium.com/p/46cf5a791f49</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[setneedslayout]]></category>
            <category><![CDATA[view-controller]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[viewdidlayoutsubviews]]></category>
            <dc:creator><![CDATA[UdayKiran M]]></dc:creator>
            <pubDate>Tue, 22 Nov 2016 09:40:43 GMT</pubDate>
            <atom:updated>2019-07-20T11:41:59.126Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Y32CjL6uA8ad0em-" /><figcaption>Photo by <a href="https://unsplash.com/@halgatewood?utm_source=medium&amp;utm_medium=referral">Hal Gatewood</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>When bounds change for a ViewControllers View, this method is called after the positions and sizes of the subviews have changed.</p><ol><li>So this is our chance to make changes to view after it has laid out its subviews, but before it is visible on the screen.</li><li>Any changes that depending on bounds have to be done, we can do here and not in ViewDidLoad or ViewWillAppear.</li><li>While ViewDidLoad &amp; ViewWillAppear, the frame, and bounds of a view are not finalized. So when AutoLayout has done its job of fixing mainView and it’s subviews, this method is called.</li></ol><p><em>When using auto layout, the framework does not call layoutSubviews every time. This is called in these cases.</em></p><ul><li><strong>Rotating a device:</strong> only calls layoutSubview on the parent view (the responding viewController’s primary view)</li><li>Its own bounds (not frame) changed. (The bounds are considered changed only if the new value is different, including a different origin.)</li><li>A subview is added to the view or removed from the view.</li><li>Your application forces layout to occur by calling the setNeedsLayout or layoutIfNeeded method of a view.</li><li>Scrolling a UIScrollView causes layoutSubviews to be called on the scrollView, and its superview.</li></ul><blockquote>Note: The call for viewDidLayoutSubviews also depends on various factors like auto-resize mask, whether Auto-Layout is used or not, and whether the view is in view hierarchy or not.</blockquote><p>I hope you will like this. 😊 Thanks for reading. 🎉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46cf5a791f49" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>