<?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 Samuel Kay on Medium]]></title>
        <description><![CDATA[Stories by Samuel Kay on Medium]]></description>
        <link>https://medium.com/@skay21?source=rss-b96cd8d8b5de------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Samuel Kay on Medium</title>
            <link>https://medium.com/@skay21?source=rss-b96cd8d8b5de------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 01:28:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@skay21/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[Going Back to the Drawing Board:]]></title>
            <link>https://medium.com/@skay21/going-back-to-the-drawing-board-ccb9d28a440c?source=rss-b96cd8d8b5de------2</link>
            <guid isPermaLink="false">https://medium.com/p/ccb9d28a440c</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[closures-functions]]></category>
            <category><![CDATA[beginner]]></category>
            <dc:creator><![CDATA[Samuel Kay]]></dc:creator>
            <pubDate>Thu, 16 Dec 2021 17:29:34 GMT</pubDate>
            <atom:updated>2021-12-16T17:31:35.476Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>My Experience Learning Closures in SwiftUI</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f3-oEVRlCofLHECnU6X0rQ.jpeg" /></figure><p>Learning a new language is a daunting task. That’s probably the reason why most high schools require you to do so in order to graduate. Even if you don’t stick with it or become fluent in it, the challenge of learning a new language can help you find new ways to overcome academic adversary. Over the past two months, I have both struggled and persevered learning the fundamental concepts of SwiftUI. Today, I’d like to share my experience trying to understand the concept of Closures in SwiftUI, and how I conquered my first major roadblock learning this new language.</p><p><strong>The Beginning</strong></p><p>Before I started learning the SwiftUI framework, I had zero prior coding experience. I knew that the path forward would be very difficult, but thankfully, I was recommended Paul Hudson’s <a href="https://www.hackingwithswift.com/">Hacking with Swift</a> series, and that has been my primary resource during this learning process. Hudson has a program called <a href="https://www.hackingwithswift.com/100/swiftui">100 Days of SwiftUI</a> that breaks down a lot of the basics through digestible videos and challenging exercises. Fortunately, I had great success with the first few days of the program, and concepts such as functions, loops, and if statements came fairly easy to me. However, I was ready to give up when we started digging into Closures.</p><p><strong>Closures are very difficult</strong></p><p>Even Hudson prefaces <a href="https://www.hackingwithswift.com/100/swiftui/9">his lesson on Closures</a> by stressing how challenging this concept can be for new Swift UI learners. I can confirm this is true. In layman’s terms, Closures are functions that can be passed through a variable. This concept took me awhile to grasp, so it’s okay if you’re still confused because I’m going to break down an example that made it all click for me.</p><pre>let favoriteArtists = [&quot;Kanye West&quot;, &quot;Kendrick Lamar&quot;, &quot;Kid Cudi&quot;, &quot;Big Sean&quot;, &quot;Baby Keem&quot;]</pre><pre>// this creates an array of strings</pre><pre>let reverseFavoriteArtists = favoriteArtists.sorted(by: {(artist1: String, artist2: String) -&gt; Bool in</pre><pre>return artist1 &gt; artist2</pre><pre>})</pre><pre>// this will sort the array from Z to A, as opposed to A to Z</pre><pre>print(reverseFavoriteArtists)</pre><pre>// this will print your newly sorted array</pre><p>In this exercise, we had to take an existing function in SwiftUI called sorted() and manipulate it to do something different from its native use. Typically, the sorted() function will accept two parameters from an array and return a Boolean (either a true or false value). In the example above, we had to create a closure that would yield a reverse sort function, so that the strings would sort from “Z to A” as opposed to “A to Z”.</p><p>While following along with this Hacking with Swift video, I was incredibly confused and had a ton of questions. Why are there only two parameters when we have five strings in the array? How does Swift determine that one letter in the alphabet is greater than another? It’s only the 10th day of the program, so why am I not getting this? Needless to say, I felt pretty defeated. After going down a Youtube rabbit hole to find other videos covering the same subject, I still did not understand the code I wrote in this exercise. I had to go back to the drawing board…literally.</p><p><strong>When in doubt, grab a pen and paper</strong></p><p>My friends (who are professional software engineers) have advised me that if I am ever having trouble understanding or writing a line of code, then the best thing to do is to just write it out. Truthfully, I never really believed in this process until I hit a wall with Closures. This concept was the breaking point for me where I finally grabbed a pen and paper from my backpack, and tried this method of learning.</p><pre>let numbers = [5, 1, 9, 7, 4, 8]</pre><pre>let reverseNumbers = numbers.sorted(by: {(number1: Int, number2: Int) -&gt; Bool in</pre><pre>return number1 &gt; number2</pre><pre>})</pre><pre>print(reverseNumbers)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H9RAtRQHRb3b7y7UaekG5A.png" /><figcaption>Handwritten notes breaking down the “reverseNumbers” example above</figcaption></figure><p>Instead of using an array of strings, I decided to try this example again using integers because the concept of one letter being “bigger” than another was breaking my brain. On my piece of paper, I determine whether number1 is greater than number 2 for each number in the array, and then rearrange the order of the array based on whether or not the result is true or false. After running this test for each value, you will end up with an array of numbers sorted from largest to smallest. This may sound like a tedious process, but going through this exercise helped me understand the logic of why the original code worked and how I can then apply the same framework to an array of strings instead.</p><p><strong>The struggle is real, but it’s all part of the journey</strong></p><p>Although I have only been learning the Swift UI framework for a little while, I’m very confident that Closures will be the first of many concepts that I have a tough time initially understanding. Despite the vast amount of coding videos and articles on the internet, these resources won’t always be the ultimate teacher that’ll make every aspect of Swift UI crystal clear. Sometimes, you need to take a step back, believe in yourself, and maybe, you’ll find you have the ability to work it out yourself, even if it takes writing your code down by hand to ensure everything clicks. Eventually, it will.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ccb9d28a440c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>