<?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 Thanyaluk Jirapech-umpai on Medium]]></title>
        <description><![CDATA[Stories by Thanyaluk Jirapech-umpai on Medium]]></description>
        <link>https://medium.com/@thanyalukj?source=rss-86b3e585fe57------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*QEGD5Qr-76lqR4qH.jpg</url>
            <title>Stories by Thanyaluk Jirapech-umpai on Medium</title>
            <link>https://medium.com/@thanyalukj?source=rss-86b3e585fe57------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 18:04:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thanyalukj/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[nonnull, nullable, and null_resettable for Objective-C and Swift]]></title>
            <link>https://medium.com/@thanyalukj/nullability-keywords-and-interoperability-between-objective-c-and-swift-220338af958b?source=rss-86b3e585fe57------2</link>
            <guid isPermaLink="false">https://medium.com/p/220338af958b</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Thanyaluk Jirapech-umpai]]></dc:creator>
            <pubDate>Mon, 23 Nov 2015 22:30:00 GMT</pubDate>
            <atom:updated>2015-12-03T00:14:26.217Z</atom:updated>
            <content:encoded><![CDATA[<p>The challenge of working with the app that has been developed before Apple announced Swift as their new programming language in WWDC14 is try to introduce Swift in the existing code base and hope that it will work well with Objective-C.</p><p>One important problem is Objective-C references to objects using raw pointers that could be NULL (or nil). In Swift, all values (structure and object references) are guaranteed to be non-null. Importing the Objective-C pointers, you are forced to wrap Objective-C references with Optional type which is not pleasant in Swift world.</p><p>So, Apple has introduced the nullability annotations to designate whether a parameter types, property type, or return type can have NULL value by using the <strong>nullable</strong>, <strong>nonnull</strong>, and <strong>null_resettable</strong> keywords.</p><ul><li><em>nonnull</em> keywords are imported by Swift as a <em>non-optional</em></li><li><em>nullable</em> keywords are imported by Swift as an <em>optional</em></li><li>Types declared without a nullability annotation are imported by Swift as <em>implicitly unwrapped optional</em></li><li><em>null_resettable</em> keyword is an interesting one. It took be a while to know what does it mean because Apple’s Developer reference doesn’t give much details.I googled and found 2 sources which are <a href="http://nshipster.com/swift-1.2/">http://nshipster.com/swift-1.2/</a> and <a href="https://developer.apple.com/library/mac/releasenotes/DeveloperTools/RN-Xcode/Chapters/xc6_release_notes.html">https://developer.apple.com/library/mac/releasenotes/DeveloperTools/RN-Xcode/Chapters/xc6_release_notes.html</a><br>Apple explains that null_resettable is used to express the nullability of <em>properties (only) </em>whose setters allow nil (to “reset” the value to some default) <em>but</em> whose getters never produce nil (because they provide some default instead) An example of null_resettable given by Apple is tintColor in UIView, which could be any colours or could be reset to system colour.</li></ul><h4>Using null_resettable</h4><p>I created a sample project to explore on null_resettable quickly. And Just like what Apple said.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*Y2OL-R5erR28ehecUVBAGg.png" /><figcaption>null_resettable property</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*x4B6MEB6vPUVc9DzFJL35g.png" /><figcaption>warnings caused by null_resettable property</figcaption></figure><p>So, to handle this, I have to implement setter and getter like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d45090bde27067e9375032d4cf5e712/href">https://medium.com/media/0d45090bde27067e9375032d4cf5e712/href</a></iframe><h4>What I love about Nullability keywords is.</h4><p>In Swift land, everything work as expected. Swift even initialise the object with the correct values. For example, when I defined nonnull on aFirstName property of a Person class. Then, when I create a Person class in Swift. Swift put empty string into the aFirstName property for me automatically!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/41ee37667cd004fc4580e646e95e902b/href">https://medium.com/media/41ee37667cd004fc4580e646e95e902b/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/97e8e911311c2f4354cb8d90e8fdfb9c/href">https://medium.com/media/97e8e911311c2f4354cb8d90e8fdfb9c/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/1*xeQCTFigvuyKJpdu0ezLZA.png" /><figcaption>Correctly defined types in Swift</figcaption></figure><h4>But wait… it’s All or Nothing</h4><p>Once I start adding them in one of properties. The ones that I haven’t added to has a warning “missing a nullability type specifier”. So, do find some times for adding these keywords. Otherwise, you might end up with a lot of warnings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*4BNO-hwJfE711d1_0tfHbA.png" /><figcaption>A warning of missing nullability type specifier</figcaption></figure><h4>Also: Objective-C doesn’t treat nullability like Swift</h4><p>I created another Objective-C class to initialise Person and print the firstName. It turn out that aFirstName which I declared as nonnull is actually null. When trying to set aFirstName to null, Xcode will give you a warning. But not when initialising the class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/efbf6a9cb333bcaa9519f9bffa2fbf51/href">https://medium.com/media/efbf6a9cb333bcaa9519f9bffa2fbf51/href</a></iframe><p><strong>Initialising A class that has a <em>nonnull</em> property could give you a <em>null</em> value in Objective-C!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=220338af958b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Closure and Unowned References in Swift]]></title>
            <link>https://medium.com/@thanyalukj/closure-and-unowned-references-in-swift-457582824975?source=rss-86b3e585fe57------2</link>
            <guid isPermaLink="false">https://medium.com/p/457582824975</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift-programming]]></category>
            <dc:creator><![CDATA[Thanyaluk Jirapech-umpai]]></dc:creator>
            <pubDate>Tue, 17 Nov 2015 00:26:06 GMT</pubDate>
            <atom:updated>2015-11-23T22:31:24.045Z</atom:updated>
            <content:encoded><![CDATA[<p>After coming back from the pragma conference in October, I was inspired by a lot of people in the conference to write a blog about what I’ve learn. So, here is my first blog post.</p><p>This week, I’ve been playing with UITextField inside UITableViewCell. I wanted to update the ViewModel once the user typed in the textfield. My common approach is to use delegate/protocol patterns.</p><p>I set UITextFieldDelegate on the UITableViewCell. Then, created a protocol and delegate on UITableViewCell that will handle updating text in viewModel. My code looks like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7711dc51db6d40af0f98667939770de/href">https://medium.com/media/d7711dc51db6d40af0f98667939770de/href</a></iframe><p>Then, I set ViewController as a delegate of the UITableViewCell and implement the function as follows</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/79283a7dd5f244159a6869ecd2ce6c0c/href">https://medium.com/media/79283a7dd5f244159a6869ecd2ce6c0c/href</a></iframe><p>Everything looks fine. But I felt there is a bit of a boiler plate for setting protocol, delegate, and then, implement the function. I have another idea.</p><h4><em>How about using closure instead of delegate?</em></h4><p>I removed TextFieldCellDelegate protocol and replaced it with closure</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/768f625f9f55aeee50a3c9168dc1e731/href">https://medium.com/media/768f625f9f55aeee50a3c9168dc1e731/href</a></iframe><p>In ViewController, I passed closure to the UITableViewCell</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64cb6665cd70d30c40b6c26efdafc9d0/href">https://medium.com/media/64cb6665cd70d30c40b6c26efdafc9d0/href</a></iframe><p>The important part is <strong>[unowned self].</strong> This tells the cell not to hold a strong reference to ViewController. But why do I use unowned reference instead of weak? Apple document states it clearly that <em>“Like weak references, an unowned reference does not keep a strong hold on the instance it refers to. Unlike a weak reference, however, an unowned reference is assumed to always have a value”</em>.</p><p>In my case, there is always be ViewController. Another benefit of <strong>unowned reference</strong> is it’s <strong>nonoptional</strong>. No unwrap required each time it is used. Happy days! I like shorter codes ;)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=457582824975" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>