<?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 Szy on Medium]]></title>
        <description><![CDATA[Stories by Szy on Medium]]></description>
        <link>https://medium.com/@nahive?source=rss-7ffcf3529180------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1Zkw9_qnK__dh-Vn3_vExA.jpeg</url>
            <title>Stories by Szy on Medium</title>
            <link>https://medium.com/@nahive?source=rss-7ffcf3529180------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 22:09:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nahive/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 range containment operator]]></title>
            <link>https://medium.com/@nahive/swift-range-containment-operator-3ba838fb8487?source=rss-7ffcf3529180------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ba838fb8487</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[protocol-oriented]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Szy]]></dc:creator>
            <pubDate>Fri, 21 Apr 2017 03:26:14 GMT</pubDate>
            <atom:updated>2017-04-21T06:01:42.709Z</atom:updated>
            <content:encoded><![CDATA[<p>So not everyone knows ~= operator — it’s an <strong>pattern matching operator to check whether the</strong> <strong>range on the left includes the value on right</strong>. The definition of this function goes like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/646cdbb7b7fafd0213960117b108548d/href">https://medium.com/media/646cdbb7b7fafd0213960117b108548d/href</a></iframe><p>It’s basically the same function as contains just wrapped in operator.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d62b50967c2cc59b355ea707f0c5dc64/href">https://medium.com/media/d62b50967c2cc59b355ea707f0c5dc64/href</a></iframe><p>Usage of the function is the same as the use of the operator.</p><p>(1...10).contains(5) // true</p><p>which is the same as</p><p>1...10 ~= 5 // true</p><p>So it makes sense that following like <strong>doesn’t work.</strong></p><p>(5).contains(1...10) // failure</p><p>5 ~= 1...10 // failure</p><p>But depending whether the user knows where does ~= come from it may be not obvious why the usage of the operator is one way only. In the written form the word contains implicates the left side is an <strong>container </strong>for the <strong>element</strong> on the right side. Like <em>basket </em><em>contains fruits</em>.</p><h3>So what’s the point of this post?</h3><p>While I understand the reasoning why ~= operator is one sided — but for me it’s somehow against the intuition. Normally for if&#39;s I write</p><p>if someVariable == 3 { doSomething() } ,</p><p>so for me it’s more natural to write</p><p>if someVariable ~= 1...3 { doSomething() } ,</p><p>which is forbidden by default.</p><h3>Solution</h3><p>So I’ve created simple extension that allows both way usage of this operator to help my against going the logic and reasoning intuition.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/46327c6fd42d9fa9cc06199c402ba5e8/href">https://medium.com/media/46327c6fd42d9fa9cc06199c402ba5e8/href</a></iframe><p>Hope that anyone likes going against the grain and finds this useful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ba838fb8487" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>