<?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 Nate Chan on Medium]]></title>
        <description><![CDATA[Stories by Nate Chan on Medium]]></description>
        <link>https://medium.com/@nathanwchan?source=rss-e11b9ec02e27------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*C6AN7m2k72zJEOwe5My5eg@2x.jpeg</url>
            <title>Stories by Nate Chan on Medium</title>
            <link>https://medium.com/@nathanwchan?source=rss-e11b9ec02e27------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 13 Jul 2026 10:37:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nathanwchan/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[8 ways I used ChatGPT to help me build my first SwiftUI app]]></title>
            <link>https://medium.com/swift-programming/8-ways-i-used-chatgpt-to-help-me-build-my-first-swiftui-app-f30dd753b5ec?source=rss-e11b9ec02e27------2</link>
            <guid isPermaLink="false">https://medium.com/p/f30dd753b5ec</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Nate Chan]]></dc:creator>
            <pubDate>Thu, 16 Mar 2023 16:25:21 GMT</pubDate>
            <atom:updated>2023-03-16T16:25:21.398Z</atom:updated>
            <content:encoded><![CDATA[<p>I built my first SwiftUI app in only one week, using ChatGPT to teach me SwiftUI concepts, write code for me, solve problems quickly, and ultimately launch a fully working app in SwiftUI to the App Store.</p><p>Without ChatGPT, it would’ve easily taken me 2–3x longer and a LOT of extra, tedious work. Here are 8 ways I prompted ChatGPT to level up my coding process…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UeT-CRJ1lRW7rp0XHKUhzw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*18GeqNK-9EBv9Let6Mxe8A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z-FL33NsSmTiOP73J4BFmA.png" /><figcaption>My first SwiftUI app — generate custom AI stories for your kids, powered by ChatGPT (yes, very meta)!</figcaption></figure><h3>1. Use equivalence</h3><p>I asked ChatGPT how to do things in SwiftUI using context I understood well — in this case, Swift. Prompting with “what’s the equivalent of XYZ in &lt;language&gt;” was a quick way to help me understand concepts through a familiar language, alongside copy-paste-ready starter code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fGEiNQyIli85cglaIrNgwg.png" /></figure><h3>2. Write code for me</h3><p>ChatGPT acted as my ghostwriter for a ton of tasks. There was no need to search for example blog posts anymore. I just told ChatGPT what I wanted, and occasionally even pasted in my existing code for it to update — and voila, the code was written for me!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JiE6UCQ8KUsuljCJX7C4lw.png" /></figure><h3>3. Error detection</h3><p>When I couldn’t find a bug or was hitting a pesky error, I just pasted in my code to have ChatGPT explain what was wrong! It was remarkable at spotting issues and giving clear explainers, letting me avoid having to Google search for generic error messages. Bye bye hundreds of StackOverflow tabs!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PZp6vHwN_Zbrsv1N0d8jyQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3P5VV3n0Vm_ODRRqKJE7Pw.png" /></figure><h3>4. Deep understanding</h3><p>I treated ChatGPT like a mentor. Asking high-level questions led to detailed answers with examples to help me better understand concepts. I then asked follow-up questions when I wanted to know more — again, just as I would with a real-life mentor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NWRwaiYvsFyJIEaCQWpVXA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wwOTUHrq6ulhpIqMd9ZhXw.png" /></figure><h3>5. How-to help</h3><p>When I needed help with setup or tooling, ChatGPT provided step-by-step instructions on how to do it in Xcode. It completely beat sifting through Apple documentation or looking for tutorials!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z1BQC_lLElU8xcwJoI9MVA.png" /></figure><h3>6. Hard-to-ask questions</h3><p>I came across many questions that Google simply didn’t have the answer to. In this case: what was the system name for what many use as the “settings” icon (⚙️)? Somehow, ChatGPT nailed it — and even wrote out the syntax on how to use it in SwiftUI!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c3NOLby3jbdd4j1SZWJvZw.png" /></figure><h3>7. Gather summarized info</h3><p>At one point I was designing a part of my UI where screen dimensions across device models were a major factor. So I asked ChatGPT to gather all that information for recent iPhone models and I magically had everything I needed, neatly summarized!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gftMBU7dxI7DLqd8RuOIXA.png" /></figure><h3>8. Format anything</h3><p>This one was a trifecta. I needed:</p><ol><li>a bunch of story prompt ideas</li><li>variety in their wording, in a specific format</li><li>the output as an array of strings in Swift</li></ol><p>ChatGPT saved me from having to do a ton of manual work or write a custom Python script. I just copy-and-pasted the array of strings straight into Xcode!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y0JqMohFwjx1-6x3lLoVrQ.png" /></figure><h3>Before you go…</h3><p>ChatGPT has been a huge productivity boost for me, both as an experienced developer but also as a developer always learning new languages and concepts. I hope this post helps with using ChatGPT to level up your coding process!</p><p>And for the parents out there, check out my new SwiftUI app for generating custom AI stories for your kids, powered by ChatGPT (yes, very meta)!</p><p><a href="https://apps.apple.com/us/app/storytime-ai/id6446004918">‎Storytime AI</a></p><p>You can reach me on Twitter <a href="https://twitter.com/nathanwchan">@nathanwchan</a>, or leave a comment below!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f30dd753b5ec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swift-programming/8-ways-i-used-chatgpt-to-help-me-build-my-first-swiftui-app-f30dd753b5ec">8 ways I used ChatGPT to help me build my first SwiftUI app</a> was originally published in <a href="https://medium.com/swift-programming">Swift Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Inside the 360iDev conference through the eyes of a first-timer]]></title>
            <link>https://medium.com/free-code-camp/inside-the-360idev-conference-through-the-eyes-of-a-first-timer-f1f639c7e52a?source=rss-e11b9ec02e27------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1f639c7e52a</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[life-lessons]]></category>
            <dc:creator><![CDATA[Nate Chan]]></dc:creator>
            <pubDate>Wed, 01 Nov 2017 16:24:55 GMT</pubDate>
            <atom:updated>2017-11-01T17:08:10.036Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mfxLUqAGf6TK6lqZwX_12w.jpeg" /><figcaption>Keynote by <a href="https://twitter.com/khanlou">@khanlou</a> — Photo credit: Fuad Kamal <a href="https://anaara.com/">https://anaara.com/</a></figcaption></figure><p>I recently spent four jam-packed days in Denver at the <a href="https://360idev.com/">360iDev conference</a>, the largest and longest-running independent iOS/Mac conference in the world.</p><p>As a newcomer to the iOS development world, and after chatting and getting to know dozens of attendees, it occurred to me that I was very likely one of the least experienced iOS developers at the conference.</p><p>I figured writing about my conference experience could bring a fresh perspective to those just starting out in iOS, as well as to those who have been attending 360iDev since the very beginning.</p><p>I’ve been a full-stack engineer for the past few years, but recently took the plunge and quit my job to pursue a career in iOS. I’ve now been working in iOS and Swift for about three months, and wrote a bit about my experience ramping-up <a href="https://medium.com/swift-programming/10-things-i-like-about-swift-7bbd40cabb79">here</a>. In the past, I’ve attended Python and web conferences, but never one related to iOS.</p><p>360iDev was the most impactful conference I’ve ever attended.</p><h4>Environment</h4><p>All of the conferences I’ve attended in the past boasted about having thousands of attendees. 360iDev was much smaller — 270 attendees this year. You start bumping into the same people. You start forming connections. You start building friendships.</p><p>Due to its smaller size, the conference felt almost casual, which was an entirely good thing. Many events were organized informally and spontaneously via the conference Slack team and the <a href="http://beacon.party/">Beacon app</a> (created by keynote speaker <a href="https://twitter.com/khanlou">@khanlou</a>).</p><p>Lunchtime was a free-for-all at nearby food trucks and restaurants. Interest groups started popping up in Slack and Beacon — there were Magic: The Gathering gatherings, doughnut runs, Pokemon Go raids, and shared rides to the airport. I felt like this <strong>casualness</strong> brought us all closer together.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1IFllCJutk6zWaOXJDTnJg.jpeg" /><figcaption>MTG FTW</figcaption></figure><p>Due to the size of the conference, the amount of physical space needed was relatively small. This year, 360iDev was hosted in a hotel. There was really only one place to mingle, check out company booths, and most importantly, grab some perpetually available coffee (nice work on that, organizers!).</p><p>This ensured that you were constantly running into people and made it easy to coordinate interest group meet-up points. It also left plenty of in-between-session time for connecting with others, as opposed to hustling to the next talk across a convention center.</p><h4>Speakers and attendees</h4><p>On my count, nearly a quarter of attendees were <a href="https://360idev.com/speakers/">speakers</a>. I would be chatting with a random attendee that I bumped into in an elevator, or walked with to a lunch spot, only to find out they were giving a talk that I was planning to attend later in the day. This happened to me several times.</p><p>I imagine WWDC would be quite different — a conference where the speakers (Apple employees) don’t stick around much, or at all, to interact with attendees. But at 360iDev, I had many opportunities (via Slack or in-person) to reach out and have conversations with speakers.</p><p>Being a popular conference in the iOS community, the conference attracts some of the best and brightest in the industry as both speakers and attendees. I must warn you as a newcomer: it might get surreal. You’ll see folks you’ve been following on Twitter sipping a Coke across the lobby, tying a shoelace in an elevator, or even peeing in the urinal next to you (this happened to me!).</p><p>So instead of “putting your heroes on a pedestal,” you’ll see them do normal, human things, and have an opportunity to talk to them.</p><h4>Talks</h4><p>The conference had three or four tracks, meaning there were typically three or four talks/sessions happening at the same time. With so many enticing talk descriptions posted, naturally, FOMO enters the mind. Which talks should I attend? What if that one is better than this<em> </em>one?</p><p>Luckily, recordings of the sessions are posted online in the coming weeks, and speakers posted slides and other material on the conference Slack channel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u-jPm8cur_sVOGVMCxk3SQ.jpeg" /><figcaption>Full house for <a href="https://twitter.com/_aijaz_">@_aijaz_</a>’s session on Advanced Debugging with Xcode — Photo credit: Fuad Kamal <a href="https://anaara.com/">https://anaara.com/</a></figcaption></figure><p>The speakers at 360iDev (at least the ones I went to) typically started with <strong>why</strong><em> </em>they were speaking about their topic. They then discussed <strong>why</strong><em> </em>it was important to them personally or professionally, rather than jumping straight into <strong>what</strong><em> </em>they were talking about.</p><p>This format differs from the sessions at WWDC. Those are more focused on the future and what’s new. Watching the speakers at 360iDev talk about what they are working on <strong>right now</strong> really resonated with me. As a newcomer to the field, it helped me understand their daily struggles and thought processes as iOS developers. And I heard so many tips and strategies to overcome those struggles.</p><p>The tracks were also structured so that each session was suitable for developers at all levels of expertise. The talk descriptions were clear when topics were advanced, and I didn’t feel like any of the presentations I attended were too far over my head. None of the speakers assumed extensive prior knowledge on their topics.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*5L1xKU1crvaaAJH5YVmUfQ.png" /><figcaption>Did I mention the occasional mind-blowing talk? This is what the chatter in the conference Slack looked like during <a href="https://twitter.com/_aijaz_">@_aijaz_</a>’s talk.</figcaption></figure><p>For a great overview of talk highlights, see <a href="https://www.raywenderlich.com/169338/360idev-2017-conference-highlights">this post</a> from attendee, speaker, and podcaster <a href="https://twitter.com/timmitra">@timmitra</a>.</p><h4>(My) Themes and Takeaways</h4><p>The state of the union keynote had a slide that rang true for me at 360iDev. It simply said: “<strong>Help others become who they are.</strong>”</p><p>Throughout the conference, I would bump into attendees I got to know. They would then introduce me to others they thought I should meet. They pointed me to open-source tools they thought I should check out for my projects. And I even got offers to proof-read this very article you’re reading right now. There was an atmosphere of <strong>helpfulness</strong> that carried through those four days.</p><p>I also felt a sense of enthusiasm that I really hadn’t felt at a conference before. Evening social events were filled with conversations about current projects, ideas for next projects, newly discovered features of the Swift language, and a general excitement for iOS development.</p><p>The nature of the fast-paced app industry likely has a lot to do with this. Still, it was hard to come away from 360iDev without feeling inspired and motivated within the firm embrace of the community.</p><p>I cannot recommend 360iDev enough to those considering attending an iOS conference in the future. For an introvert like myself, I know full days of conference socializing can be exhausting. But 360iDev broke many of those barriers and created a particularly friendly and inviting environment for its attendees. Denver’s also a pretty cool spot :)</p><p>Until next time, <a href="https://twitter.com/360iDev">@360iDev</a>!</p><p>You can reach me on Twitter <a href="https://twitter.com/nathanwchan">@nathanwchan</a>, or leave a comment below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1f639c7e52a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/inside-the-360idev-conference-through-the-eyes-of-a-first-timer-f1f639c7e52a">Inside the 360iDev conference through the eyes of a first-timer</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handling empty optional strings in Swift]]></title>
            <link>https://medium.com/ios-os-x-development/handling-empty-optional-strings-in-swift-ba77ef627d74?source=rss-e11b9ec02e27------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba77ef627d74</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <dc:creator><![CDATA[Nate Chan]]></dc:creator>
            <pubDate>Wed, 06 Sep 2017 19:43:18 GMT</pubDate>
            <atom:updated>2017-09-10T21:46:14.291Z</atom:updated>
            <content:encoded><![CDATA[<p>String optionals in Swift are a little peculiar. The String? type sort of has two “invalid” values: nil and &quot;&quot;. This can make it cumbersome to handle and ripe for bugs and unexpected behavior.</p><p>Take for example a UITextField ’s text property, which is a String?. We <em>could</em> write the following code to appropriately alert the user when the text field is left empty, while unwrapping the text string for later use:</p><pre>if let title = textField.text {<br>    if title.isEmpty {<br>        // Alert: textField is empty!<br>    }<br>    // title String is now unwrapped, non-empty, and ready for use<br>}</pre><p>Any combination of guard let or optional chaining, like textField.text?.isEmpty ?? true could’ve been used here as well. Either way, the implementation gets messy, and you’ll be dealing with multiple and/or nested conditionals.</p><p><a href="https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Extensions.html">Swift extensions</a> to the rescue!</p><p>Extensions allow you to add new functionality to an existing class, structure, enumeration, or protocol type. With a where clause, you can restrict the extension to specific or conforming types.</p><p>So how can we apply this to handling the empty string value for a String?? Let’s define a new computed property nilIfEmpty in an extension restricted to optional Strings, which transforms an empty String to nil or returns the original String?.</p><pre>extension Optional where Wrapped == String {<br>    var nilIfEmpty: String? {<br>        guard let strongSelf = self else {<br>            return nil<br>        }<br>        return strongSelf.isEmpty ? nil : strongSelf<br>    }<br>}</pre><p>Now, this allows us to clean up our above code for detecting when a text field is empty to alert the user, while unwrapping the text string:</p><pre>guard let title = textField.text.nilIfEmpty else {<br>    // Alert: textField is empty!<br>    return<br>}<br>// title String is now unwrapped, non-empty, and ready for use</pre><p>Pretty, ain’t it?</p><p>This extension could also come in handy when used with higher-order functions like map or flatMap:</p><pre>let stuff = [&quot;nate&quot;, &quot;&quot;, nil, &quot;loves&quot;, nil, &quot;swift&quot;, &quot;&quot;]</pre><pre>let a = stuff.map { $0.nilIfEmpty }<br>print(a) // [Optional(&quot;nate&quot;), nil, nil, Optional(&quot;loves&quot;), nil, Optional(&quot;swift&quot;), nil]</pre><pre>let b = stuff.flatMap { $0.nilIfEmpty }<br>print(b) // [&quot;nate&quot;, &quot;loves&quot;, &quot;swift&quot;]</pre><h3>Before you go…</h3><p>Have you found any other approaches for dealing with empty optional strings? I’d love to hear them. Leave a comment below, or you can reach me on Twitter <a href="https://twitter.com/nathanwchan">@nathanwchan</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba77ef627d74" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ios-os-x-development/handling-empty-optional-strings-in-swift-ba77ef627d74">Handling empty optional strings in Swift</a> was originally published in <a href="https://medium.com/ios-os-x-development">iOS App Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[10 things I like about Swift]]></title>
            <link>https://medium.com/ios-os-x-development/10-things-i-like-about-swift-7bbd40cabb79?source=rss-e11b9ec02e27------2</link>
            <guid isPermaLink="false">https://medium.com/p/7bbd40cabb79</guid>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <dc:creator><![CDATA[Nate Chan]]></dc:creator>
            <pubDate>Thu, 03 Aug 2017 16:45:30 GMT</pubDate>
            <atom:updated>2020-09-20T22:15:34.986Z</atom:updated>
            <content:encoded><![CDATA[<h4>And how I went from complete beginner to feeling confident in building iOS apps in Swift</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*zM_DWuIhn09fQm9relAI2A.jpeg" /><figcaption>These are a few of my favorite things… about Swift</figcaption></figure><p>After just over 2 months of immersing myself in the Swift language and tinkering with iOS development, I thought I’d put together my thoughts on why I’ve begun to fully enjoy working in Swift and provide some resources on how I ramped-up from complete beginner to feeling confident in building iOS apps in Swift.</p><p>I come from a full-stack development background, which really means I can’t call myself an expert in any particular field of computer science :). But I’ve worked professionally in Python, Scala and JavaScript, among a few others, so my perspective likely bleeds from my past experiences working in those languages.</p><p><em>Note: I have been working in Swift 3, Xcode 8 and iOS 10.</em></p><h4>1. Readability</h4><blockquote>Programs must be written for people to read, and only incidentally for machines to execute. — Harold Abelson</blockquote><p>This is a principle I try to live by as a software engineer. So far, Swift has felt expressive and easy to use, while maintaining readability for future-me (or anyone else). It has the feel of what I would think a “modern” language should be, leaning towards simple and as-you-would-expect syntax, doing away with noisy symbols and clunky syntax as a natural evolution from Objective-C.</p><p>Here’s an example of how some simple string formatting compares between Objective-C, Swift and Python:</p><pre>// Objective-C<br>NSString *name = @&quot;Nate&quot;;<br>NSString *str = [NSString stringWithFormat:@&quot;Hello %@, how are you today?&quot;, name];</pre><pre>// Swift<br>let name = &quot;Nate&quot;<br>let str = &quot;Hello \(name), how are you today?&quot;</pre><pre>// Python<br>name = &quot;Nate&quot;<br>str = &quot;Hello %s, how are you today?&quot; % name</pre><p>There were several Swift-isms that I had to get used to, and still more I’m learning everyday, but Swift has overall been an approachable language to read and write code in.</p><p>For a great article on some intermediate Swift syntax, <a href="https://medium.com/swift-programming/swift-syntax-cheat-codes-9ce4ab4bc82e">check this out</a>.</p><h4>2. Functional programming</h4><p>Swift isn’t purely a functional programming language, but firmly embraces higher-order functions such as <em>map</em>, <em>filter</em>, <em>reduce</em> and <em>flatMap</em>.</p><p>As a brief overview of how functional programming can simplify your code, here’s an example:</p><pre>// Add 5 to each number in an array, and return the even results<br>let numbers = [1, 2, 3, 4, 5]</pre><pre>// The traditional, imperative way<br>var newNumbers: [Int] = []<br>for number in numbers {<br>    let newNum = number + 5<br>    if newNum % 2 == 0 {<br>        newNumbers.append(newNum)<br>    }<br>}</pre><pre>// The functional, declarative way<br>var newNumbersFP = numbers.map { $0 + 5 }.filter { $0 % 2 == 0 }</pre><p>You could argue that the imperative way is more readable, particularly when functional chaining and code complexity gets out of hand, but think of these higher-order functions as an additional tool in your tool belt for certain use-cases.</p><p>Higher-order functions can be extremely powerful, so for a deeper dive, see <a href="https://medium.com/@mimicatcodes/simple-higher-order-functions-in-swift-3-0-map-filter-reduce-and-flatmap-984fa00b2532">this article</a>.</p><h4>3. Type safety</h4><p>Swift introduces the <em>Optional</em> type, which safely handles the absence of a value. It forces us to handle the <em>nil</em> case explicitly to ensure we’re not making any bad assumptions about what a variable holds.</p><p>For example, when a variable is an optional<em> String</em>, we know that either the variable is a <em>String</em> OR the variable doesn’t have a value. Swift offers a few ways for us to handle this in a safe way (called <em>safe unwrapping</em>):</p><ul><li>guard:</li></ul><pre>guard let str = strOptional else {<br>    return<br>}<br>// str is now safely unwrapped and is guaranteed to be of<br>// String type from here on</pre><ul><li>if let:</li></ul><pre>if let str = strOptional {<br>   print(&quot;This is a string: \(str)&quot;)<br>}</pre><ul><li>optional chaining:</li></ul><pre>class Person {<br>    var pet: Pet?  // the ? means pet is a Pet optional<br>}</pre><pre>class Pet {<br>    var numberOfPets: Int = 3<br>}</pre><pre>let me = Person()<br>let numberOfPets = me.pet?.numberOfPets<br>// numberOfPets is an optional Int and will be safely set to nil<br>// if pet is nil</pre><pre>// Or use &quot;if let&quot; to safely unwrap:<br>if let petCount = me.pet?.numberOfPets {<br>    print(&quot;Pet count is \(petCount)&quot;)<br>}</pre><ul><li>nil and conditional coalescing:</li></ul><pre>let numberOfPets = me.pet?.numberOfPets ?? 0</pre><pre>let hasPets = numberOfPets &gt; 0 ? true : false<br>// this can be short-handed to: let hasPets = numberOfPets &gt; 0</pre><p>There’s a lot to be appreciated with type safety in Swift, and many ways to go about structuring code to be safe and readable using these approaches. It can be frustrating at first because Swift urges for explicit handling of optionals (but doesn’t <em>force</em> safety on you!… see <a href="https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html#//apple_ref/doc/uid/TP40014097-CH5-ID332">forced unwrapping</a>), making it hard to write hack-y code. But just remember, Xcode is your friend and works with you when using optionals!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*QFyIKTWS9yMIMUjD9bfysQ.png" /><figcaption>Xcode is your friend!</figcaption></figure><p>At the end of the day, Swift was built with safety in mind, intended to prevent many classes of bugs and runtime errors. It may mean that the language feels more strict, but their hope was that proper and explicit handling of types saves time in the long run.</p><h4>4. Protocol-oriented programming</h4><p>I’ll admit, this one took a bit of time to even begin to sink in. There is a lot out there on <a href="https://medium.com/ios-os-x-development/how-protocol-oriented-programming-in-swift-saved-my-day-75737a6af022">protocol-oriented programming</a> (POP), <a href="https://developer.apple.com/videos/play/wwdc2015/414">structs and value type semantics</a>, <a href="https://blog.daftmobile.com/keep-things-dry-e90c07e9d678">don’t repeat yourself</a> (DRY principle) and then there’s the <a href="https://developer.apple.com/videos/play/wwdc2015/408/">infamous Crusty talk</a>; so this was an overwhelming topic early on for me, and still continues to be.</p><p>But things began to click as I dove in and started restructuring my code to use protocols and protocol extensions. By implementing and conforming my classes and structs to protocols (blueprints), and defining protocol extensions (default method implementations), I started seeing patterns of reusability and more modular code, and watched as my Massive View Controllers shrunk in size becoming more manageable. A great side-effect was that I was leaning towards composition as opposed to inheritance, so I wasn’t bloating my objects by super-classing and inheriting properties and methods I didn’t need.</p><p>I’m not doing POP justice with this bullet point. There seem to be endless use-cases for taking advantage of all that Swift has to offer with using protocols and value types, and I know I’ve only scratched the surface. Post a comment if you have any POP examples worth sharing!</p><p>In addition to the links above, here are a few more resources that I found helpful as I continue to wrap my head around this topic:</p><ul><li><a href="https://developer.apple.com/videos/play/wwdc2016/419/">Protocol and Value Oriented Programming in UIKit Apps</a> — WWDC 2016</li><li><a href="https://academy.realm.io/posts/appbuilders-natasha-muraschev-practical-protocol-oriented-programming/">Practical Protocol-Oriented-Programming</a> — Natasha The Robot</li><li><a href="https://academy.realm.io/posts/tryswift-daniel-steinberg-blending-cultures/">Blending Cultures: The Best of Functional, Protocol, &amp; Object-Oriented Programming</a> — Daniel Steinberg</li></ul><h4>5. Property observers</h4><p>This is one of my favorite out-of-box features of Swift. Understanding how it works is fairly simple with an example:</p><pre>var score = 0 {<br>    willSet {<br>        print(&quot;Score is about to change to \(newValue)&quot;)<br>    }<br>    didSet {<br>        print(&quot;Score just changed from \(oldValue) to \(score)&quot;)<br>    }<br>}</pre><pre>score = 50<br>// Score is about to change to 50<br>// Score just changed from 0 to 50</pre><p>One of my favorite ways of using property observers is with updating a table view:</p><pre>var toDoListTasks: [Task] = [] {<br>    didSet {<br>        DispatchQueue.main.async {<br>            self.tasksTableView.reloadData()<br>        }<br>    }<br>}</pre><pre>toDoListTasks.append(Task(&quot;clean kitchen&quot;))<br>// table view is automatically reloaded!</pre><p>Note from Apple docs:</p><blockquote>The observers [willSet, didSet] are not called when the variable or property is first initialized. Instead, they are called only when the value is set outside of an initialization context.</blockquote><h4>6. Type inference</h4><p>The Swift compiler infers type for constants or variables, allowing you to keep your code shorter and cleaner.</p><pre>var number = 5              // Don&#39;t need to use var number: Int = 5<br>let pi = 3.14159            // pi is inferred to be of type Double<br>let stillPi = 3 + 0.14159   // Yup, still a Double</pre><pre>view.backgroundColor = .yellow   // Don&#39;t need to use UIColor.yellow</pre><h4>7. Custom function argument labels</h4><p>Another small but nice feature of Swift: custom and omitted argument labels in functions for easier-to-read code.</p><pre>func moveBox(_ box: Box, from start: Point, to end: Point) {<br>    // move the box!<br>}<br>let aBox = Box()<br>moveBox(aBox, from: Point(0,0), to: Point(5,5))</pre><p>Xcode then makes it super easy for you to fill out arguments when calling the method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*RDpu6oIv6eRkeD85oCZ_zQ.png" /><figcaption>Again, Xcode is your friend!</figcaption></figure><h4>8. Swift Playground</h4><p>Since Swift’s initial release in 2014, playgrounds in Xcode have been around, allowing developers to quickly experiment with live code in an interactive environment, instead of having to continually go through a compile-run-test cycle.</p><p>Coming from a Python environment, I would have felt empty inside if this wasn’t possible with Swift, but I think playgrounds are to be appreciated for a compiled language! Swift playgrounds aren’t perfect and can get bogged down and slow to use in Xcode, but it’s still been super helpful as I’ve ramped-up and experimented with Swift code.</p><p>I haven’t yet used playgrounds for UI mockups, but I can only imagine how powerful and lightweight it must feel for those used to developing for iOS in Objective-C without the ability to quickly experiment.</p><h4>9. Open-source</h4><p>Want to know how Strings or Collections or anything else in the Swift standard library works? Or how about even lower-level implementation details of the Swift language? <a href="https://github.com/apple/swift">Well now you can!</a> Swift has been open-sourced since Swift 2.2, and the <a href="https://github.com/apple/swift-evolution">Swift Evolution</a> project continues to provide transparency with what’s coming in future releases of Swift.</p><p>Chris Lattner (founder of Swift) and team knew from day one that Swift would eventually be open-sourced, so kept full commit history all the way back to their very <a href="https://github.com/apple/swift/commit/afc81c1855bf711315b8e5de02db138d3d487eeb">first commit</a>. If you notice in those files, the copyright text says “Copyright © 2014–2015 Apple Inc.”, whereas the checkin was made in 2010! So it could be that 1) the team rewrote git history for some reason, 2) this was intentional to remind them that Apple wanted them to deliver in 2014–2015, or 3) Chris Lattner is a sorcerer.</p><h4>10. Swift documentation</h4><p>Apple’s Swift documentation reads like a book. They explain things in simple-to-understand English while laying out great examples, and I oftentimes find answers to my questions directly from their docs (as opposed to Stack Overflow), which I cannot say about other languages I’ve worked in.</p><p>I’ve learned about how <a href="https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html">closures</a> and <a href="https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/AutomaticReferenceCounting.html">automatic reference counting</a> work directly from the Swift docs, and even began my Swift journey on their <a href="https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/">Jump Right In</a> page by building out a simple table view app. They’ve done a really great job with these docs and I’d highly recommend going directly to them before heading to Stack Overflow when working through your next problem.</p><h4>11. Community</h4><p>Ok I couldn’t leave this one out, so it’s going to be <strong>11</strong> things I like about Swift.</p><p>The Swift community has been more than welcoming as I’ve learned the ins-and-outs of iOS development, working in Xcode and ramped-up on Swift.</p><p>First, I love how there have been standards put forth from the wild that seem to have mass adoption, like <a href="https://github.com/raywenderlich/swift-style-guide">Ray Wenderlich’s Swift style guide</a> and the super customizable <a href="https://github.com/realm/SwiftLint">SwiftLint project from Realm</a> for enforcing those standards, driven by the community. It’s given me comfort in knowing that there’s a well established way of doing things that much of the community agrees with, allowing me to focus on the important stuff.</p><p>Second, the active, online community of people who have willingly lended a helping hand as I worked through problems and had iOS/Swift related questions. Over my last couple months, I’ve leaned on the <a href="https://ios-developers.io/">iOS developers Slack group</a>, iOS developers on Twitter and countless websites and bloggers dedicated to teaching newbie iOS developers like myself.</p><p>Finally, those who built and contributed to the open-source project that is Swift. They’ve clearly built something that people love (<a href="https://insights.stackoverflow.com/survey/2017#technology-most-loved-dreaded-and-wanted-languages">4th most loved language</a>!) and we shouldn’t take for granted all the work that has paved the way to what Swift is today.</p><h4>Before you go…</h4><p>You might be saying to yourself… this dude can’t possibly have nothing bad to say about Swift?! You’re right, there are certainly things that come to mind that have frustrated me about working in the language. To name just a few: lack of modules/namespacing (although there are <a href="http://khanlou.com/2016/06/easy-namespacing-in-swift/">tricks</a>), JSON serialization using just Swift Core Libraries was a pain (I’m now using <a href="https://github.com/SwiftyJSON/SwiftyJSON">SwiftyJSON</a>) and String manipulation and various String operations were brutal to work with (for good reason; but there seem to be a lot of <a href="https://github.com/apple/swift/blob/master/docs/StringManifesto.md">improvements coming in Swift 4</a>).</p><p>I opted to stick with the positives, as my overall experience with Swift has been beyond positive. I have so much more to learn (and be frustrated with), so figured that topic can wait.</p><p>Lastly, here’s a list of places I’d recommend for those just starting to learn Swift and iOS development that really helped me:</p><ul><li><strong>START HERE</strong> AND BUILD <em>SOMETHING</em>: <a href="https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/">Jump Right In</a></li><li>Join this Slack group and say 👋: <a href="https://ios-developers.io/">ios-developers.io</a></li><li><a href="https://www.raywenderlich.com/">Ray Wenderlich tutorials</a></li><li><a href="https://m.youtube.com/channel/UCbTw29mcP12YlTt1EpUaVJw">Sean Allen YouTube videos</a></li><li>Follow iOS developers on Twitter who tweet/retweet about iOS/Swift (there are so so many, eg. <a href="https://twitter.com/NatashaTheRobot">@NatashaTheRobot</a>, <a href="https://twitter.com/hanning_thomas">@hanning_thomas</a>, <a href="https://twitter.com/gregheo">@gregheo</a>)</li><li>Listen to iOS related podcasts (if that’s your thing…). I’d recommend starting with the <a href="https://t.co/W60vf2vXHo">SwiftCoders podcast</a>.</li><li>Subscribe to iOS newsletters for well-curated content and to keep up-to-date with what’s happening in the iOS/Swift community. A few good ones are: <a href="https://iosdevweekly.com/">iOS Dev Weekly</a>, <a href="https://swiftnews.curated.co/">This Week in Swift (NatashaTheRobot)</a>, and <a href="https://www.raywenderlich.com">raywenderlich.com weekly</a>.</li><li>Browse Github and read about how other projects are structured. Good examples are the <a href="https://github.com/kickstarter/ios-oss">Kickstarter</a>, <a href="https://redditblog.com/2017/06/08/building-the-feed-for-the-reddit-ios-app/">Reddit</a> and <a href="https://github.com/artsy/eigen">Artsy</a> iOS apps (I haven’t gone through all of these myself, but they’ve been commonly recommended to me).</li><li>Try to attend local iOS/CocoaHeads meetups and <a href="https://gist.github.com/jpmartha/fbc43745677bc9bf6486d4074c2c01d5">iOS conferences</a></li><li>Generally immerse yourself, even if you don’t understand everything you read/listen/watch. It’ll click eventually.</li></ul><p>You can reach me on Twitter <a href="https://twitter.com/nathanwchan">@nathanwchan</a>, or leave a comment below!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7bbd40cabb79" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ios-os-x-development/10-things-i-like-about-swift-7bbd40cabb79">10 things I like about Swift</a> was originally published in <a href="https://medium.com/ios-os-x-development">iOS App Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>