<?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 Keshav Vishwkarma on Medium]]></title>
        <description><![CDATA[Stories by Keshav Vishwkarma on Medium]]></description>
        <link>https://medium.com/@keshavvishwkarma?source=rss-255389894285------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*aK7vlBXBIBpfHlxB.</url>
            <title>Stories by Keshav Vishwkarma on Medium</title>
            <link>https://medium.com/@keshavvishwkarma?source=rss-255389894285------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 15 Nov 2026 09:33:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@keshavvishwkarma/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 5.0 introduces a new Result type …..?]]></title>
            <link>https://medium.com/@keshavvishwkarma/swift-5-0-introduces-a-new-result-type-df1a85f8fd29?source=rss-255389894285------2</link>
            <guid isPermaLink="false">https://medium.com/p/df1a85f8fd29</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[cocoa-touch]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Keshav Vishwkarma]]></dc:creator>
            <pubDate>Fri, 12 Apr 2019 18:18:02 GMT</pubDate>
            <atom:updated>2019-04-13T04:40:07.609Z</atom:updated>
            <content:encoded><![CDATA[<p>Swift 5.0 introduces a new<em> </em><strong><em>Result type</em></strong><em> </em>that is implemented as a generic <strong><em>enum</em></strong> with two <strong><em>cases</em></strong>: .<strong>success</strong> and .<strong>failure</strong>,<strong> </strong>including an associated value in each case.</p><ul><li>A value is associated with <strong>case .success</strong> can be an anything ( depends on you.)</li><li>A value is associated with <strong>case .failure</strong> must be a <strong>type</strong> that adopts the <strong>Error</strong> protocol.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cobhFI3mVw2foUhFQ-grtQ.png" /><figcaption>A value represents either <strong>success</strong> and corresponding value or <strong>failure</strong> and corresponding error.</figcaption></figure><blockquote>Why? <a href="https://github.com/apple/swift/blob/master/stdlib/public/core/Result.swift"><strong><em>Result type</em></strong></a><strong><em> — </em></strong><em>It</em><strong><em> </em></strong><em>provides</em><strong><em> a clearer and type-safe way to handle the errors.</em></strong></blockquote><p><strong>For example — </strong>Let’s create a simple function <strong>toInteger</strong> which convert a string to an integer &amp; returns Result&lt;Int, AnErrorType&gt;. Please note that here <strong>case .success </strong>has an associated value of <strong>Int</strong> type &amp; <strong>case .failure </strong>has an associated value of <strong>AnErrorType</strong> type which adopts the <strong>Error </strong>protocol.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uYAVCX41KjWO57SqMW0CYw.png" /><figcaption>here Result&lt;Success, Failure&gt; == Result&lt;Int, AnErrorType&gt;</figcaption></figure><p>Now we can use it like that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*Gl6PcPQuTxdVPSSwoytFVw.png" /></figure><blockquote><em>So by using the </em><a href="https://github.com/apple/swift/blob/master/stdlib/public/core/Result.swift"><strong><em>Result type</em></strong></a><em>, it’s very clear that we’re getting back either result value of </em><strong><em>Int</em></strong><em> type or a strongly typed error value of type </em><strong>AnErrorType</strong><em> . It’s not possible to get </em><strong><em>all</em></strong><em> or </em><strong><em>none </em></strong><em>means</em><strong><em> </em></strong><a href="https://github.com/apple/swift/blob/master/stdlib/public/core/Result.swift"><strong><em>Result type</em></strong></a><strong><em> </em></strong><em>provides</em><strong><em> a more clearer and type-safe way to handle the errors.</em></strong></blockquote><p>Additionally, <strong><em>Result</em></strong> type supports a specific initializer that accepts a throwing closure —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZGyImRAQ8Yso4xRZ8NmAdQ.png" /></figure><p><strong>For example —</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AyBt9cICPav-cFxPJDrIsQ.png" /></figure><blockquote>That’s all for now. Thank you for reading! This is my first ever medium post. I hope this quick read gave you a brief insight into the world of new Result type introduction in the swift 5.0 leveraging the power of enum.</blockquote><p>I would really appreciate any constructive criticism which comes my way, please feel free to drop your thoughts here. Please help me spread the word by liking and sharing this post with Swift lovers around the world.</p><p>And stay tuned for more glimpses into the world of Swift.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df1a85f8fd29" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>