<?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 Ben Thomas on Medium]]></title>
        <description><![CDATA[Stories by Ben Thomas on Medium]]></description>
        <link>https://medium.com/@iOSDevBen?source=rss-f9e1cba2bf2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*8tq1BEZMlZRXm_in.jpeg</url>
            <title>Stories by Ben Thomas on Medium</title>
            <link>https://medium.com/@iOSDevBen?source=rss-f9e1cba2bf2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 15:58:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@iOSDevBen/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[Some random thoughts on graduates applying for jobs]]></title>
            <link>https://medium.com/@iOSDevBen/some-random-thoughts-on-graduates-applying-for-jobs-4490c0eae954?source=rss-f9e1cba2bf2------2</link>
            <guid isPermaLink="false">https://medium.com/p/4490c0eae954</guid>
            <dc:creator><![CDATA[Ben Thomas]]></dc:creator>
            <pubDate>Sat, 25 Sep 2021 22:39:16 GMT</pubDate>
            <atom:updated>2021-09-25T22:39:16.351Z</atom:updated>
            <content:encoded><![CDATA[<p>As a hiring manager I care a lot less about your marks. The degree proves that you can learn. Most applicants only get average marks, and there aren’t enough people with top marks to fill all the jobs.</p><p>What I want to hear is why you think I should hire you. What will make you good at the job? What will you do better than the next person? Why do you want to work for my company specifically?</p><p>When you apply for jobs, look at the qualities they say they want you to have, or the responsibilities they say you will have. Write a cover letter directly addressing those points. Talk about what excites you. What will get you out of bed in the morning and make you look forward to going to work.</p><p>I guarantee you will stand out from the crowd.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4490c0eae954" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Who are you coding for?]]></title>
            <link>https://medium.com/@iOSDevBen/who-are-you-coding-for-229277343a19?source=rss-f9e1cba2bf2------2</link>
            <guid isPermaLink="false">https://medium.com/p/229277343a19</guid>
            <category><![CDATA[teamwork]]></category>
            <category><![CDATA[pull-request]]></category>
            <category><![CDATA[introspection]]></category>
            <category><![CDATA[code-review]]></category>
            <category><![CDATA[professional-development]]></category>
            <dc:creator><![CDATA[Ben Thomas]]></dc:creator>
            <pubDate>Tue, 05 Sep 2017 22:24:52 GMT</pubDate>
            <atom:updated>2017-09-05T22:24:52.905Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*znWa0T97wnwCCzMWqd3AmA.jpeg" /></figure><p>I’ve been reflecting on the code review process after receiving feedback on my own pull request yesterday. I though I’d come up with a very succinct and efficient solution to a problem — combining model data and device capabilities to decide whether to hide a button, in just a couple of lines of code — but two other team members recommended a different approach.</p><p>Their main feedback was that they did not see the logic as obvious, which I initially completely rejected because I felt the logic was perfectly clear. But after thinking about it I recalled a principle that I firmly believe in.</p><blockquote>As a developer, you are writing your code for other developers and your future self. What seems clear now, may not be so clear in future.</blockquote><p>If more than one person feels there is a clearer way to express some logic, then it will be far more critical in the future when someone is reading that code to diagnose a bug or because they need to change some behaviour due to new business requirements.</p><p>I also realised that when we discussed their comments I spent most of the conversation trying to “win the argument”, and convince them that my code was fine. If I had begun with the mindset that this was not “my” code, but actually code for others, then the conversation would have been quite different. In fact, I probably would have just made the recommended changes immediately.</p><p>One of the trickiest parts about code reviews is there is usually more than one way to solve a problem and sometimes all the proposed solutions are “correct”. So falling back on the principle I mentioned above <em>can</em> be a quick way to find a resolution. And this reminds me that every team should have a clear set of principles — a topic for another article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=229277343a19" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TIL: UIStackViews and Autolayout warnings when hiding subviews]]></title>
            <link>https://medium.com/@iOSDevBen/til-uistackviews-and-autolayout-warnings-f25dd9bcb983?source=rss-f9e1cba2bf2------2</link>
            <guid isPermaLink="false">https://medium.com/p/f25dd9bcb983</guid>
            <category><![CDATA[uistackview]]></category>
            <category><![CDATA[autolayout]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Ben Thomas]]></dc:creator>
            <pubDate>Sun, 20 Nov 2016 22:12:40 GMT</pubDate>
            <atom:updated>2016-11-20T23:42:09.995Z</atom:updated>
            <content:encoded><![CDATA[<p>Apple introduced <a href="https://developer.apple.com/reference/uikit/uistackview">UIStackViews</a> in iOS 9 and if, like me, you’ve recently dropped support for iOS 8, and now you’re finally able to start embracing this handy feature in iOS.</p><p>I won’t try to describe how to use them — Apple has a great <a href="https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/LayoutUsingStackViews.html#//apple_ref/doc/uid/TP40010853-CH11-SW1">cookbook</a> for building your UI with UIStackViews — and things will sail along pretty smoothly until you try to leverage one of UIStackView’s <a href="https://www.google.com.au/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=2&amp;cad=rja&amp;uact=8&amp;ved=0ahUKEwin8qe9qLjQAhWBs5QKHfWTCg0QFgg_MAE&amp;url=http%3A%2F%2Fwww.dictionary.com%2Fbrowse%2Fpun&amp;usg=AFQjCNHmBfNliV5fT2BF8ALUDJvkxXf04Q">hidden</a> powers. If you set the hidden property of a view to true, the UIStackView will automatically animate the resizing and relayout of the contents. But you may see some warnings in the Xcode console when you do this. Apple also have a handy <a href="https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/TypesofErrors.html#//apple_ref/doc/uid/TP40010853-CH17-SW1">guide</a> explaining how to deal with Autolayout errors.</p><p><em>It’s tempting to skim over Apple’s documentation and just go straight for sample code on Stack Overflow, but I’ve found I’ll miss the correct solution when learning to write </em><a href="http://appstore.com/BenThomas"><em>my apps</em></a><em>.</em></p><p>So, when you hide a subview in a UIStackView you may see warnings like the following:</p><pre><strong>2016-11-21 08:44:55.874 HarkenForiPhone[47019:10150229] Unable to simultaneously satisfy constraints.</strong></pre><pre><strong>Probably at least one of the constraints in the following list is one you don&#39;t want.</strong></pre><pre><strong>Try this:<br>(1) look at each constraint and try to figure out which you don&#39;t expect;<br>(2) find the code that added the unwanted constraint or constraints and fix it.<br>(<br>&quot;&lt;NSLayoutConstraint:0x7fb88c9365a0 H:[UIView:0x7fb88c9363d0(1)]&gt;&quot;,<br>&quot;&lt;NSLayoutConstraint:0x7fb8901d5b90 &#39;UISV-hiding&#39; H:[UIView:0x7fb88c9363d0(0)]&gt;&quot;<br>)</strong></pre><pre><strong>Will attempt to recover by breaking constraint<br>&lt;NSLayoutConstraint:0x7fb88c9365a0 H:[UIView:0x7fb88c9363d0(1)]&gt;</strong></pre><pre><strong>Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.<br>The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in &lt;UIKit/UIView.h&gt; may also be helpful.</strong></pre><p>This UIStackView is laid out horizontally and one of the subviews has a width constraint of 1 with priority 1000. When the subview is hidden, the Autolayout engine correctly removes the constraint to update the layout, but it displays this disconcerting warning in the console.</p><p><em>I’ve ignored warnings like this in the past but this lead to me not noticing other runtime errors and warnings, and fortunately it’s easy to fix.</em></p><p>Just set the priority of the subview’s width constraint to 999 and the warning will go away.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f25dd9bcb983" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unit Tests and Working with Legacy Code]]></title>
            <link>https://medium.com/itty-bitty-apps/unit-tests-and-working-with-legacy-code-c32fd7c3e64e?source=rss-f9e1cba2bf2------2</link>
            <guid isPermaLink="false">https://medium.com/p/c32fd7c3e64e</guid>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swift-playgrounds]]></category>
            <category><![CDATA[xctest]]></category>
            <dc:creator><![CDATA[Ben Thomas]]></dc:creator>
            <pubDate>Fri, 11 Nov 2016 04:53:03 GMT</pubDate>
            <atom:updated>2016-11-11T05:18:32.874Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SjkHIIWstXMU1xKY8Nh7KA.jpeg" /></figure><p>Much has been written about writing good software and how to refactor a codebase when you want to add or remove features but most of the existing literature uses C or Java in it’s examples. Here I will attempt to show how iOS Developers can use XCTest to aid in maintaining legacy Swift code.</p><h3>What is legacy code?</h3><p>Legacy code is basically any existing code — it doesn’t matter how old it is. But the older it is, the less likely you are to be familiar with it — even if you wrote it. And you want to be able to modify it with confidence that you won’t break existing functionality.</p><h3>What are we trying to achieve?</h3><p>There are many reasons for having to touch legacy code but they generally fall into the following categories:</p><ul><li>Fix a bug</li><li>Change the behaviour due to a change in business rules</li><li>Extend the functionality to support a new feature</li></ul><p>If we’re lucky we don’t need to make any major changes to do any of the above, but often we need to refactor the code to achieve our goal. This could be as simple as taking a few lines of code and extracting them to a separate function, or as complicated as breaking an object up into several separate objects, resulting in the need for changes throughout the codebase wherever the old code was called from.</p><p>The problem is, we don’t want to introduce any bugs, and unless we’re intimately familiar with the app, or the codebase is very simple, it’s highly likely that we will break something.</p><h3>Unit tests are our friend</h3><p>Before we go changing any code it’s important to be sure we understand how the app functions first and be able to know if we’ve changed that functionality after we’ve changed the code.</p><p>So that I can demonstrate how unit tests can help, lets imagine we have an app that can display the name and address of a person in a UILabel. We’ll have a simple Person object and a view model with a single function that returns the text for the label.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/711004e744eb519a0378fd4720084043/href">https://medium.com/media/711004e744eb519a0378fd4720084043/href</a></iframe><p>Step 1 is to understand what this code does by writing a failing test.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a9dae6dedda1e4afeacec4afb1f8d22/href">https://medium.com/media/7a9dae6dedda1e4afeacec4afb1f8d22/href</a></iframe><p>This will fail with an error:</p><pre>XCTAssertEqual failed: (“John Appleseed, 1 Infinite Loop, Cupertino, CA”) is not equal to (“”) —</pre><p>To make our test pass we can copy the output string into the test case:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06acf02db0c3b09df96acb587ddae2ba/href">https://medium.com/media/06acf02db0c3b09df96acb587ddae2ba/href</a></iframe><h3>Refactoring</h3><p>Now that we have a unit test, we can start to refactor. So lets say we want to split the name into two separate properties on the Person class, so we can display them in two separate labels on another screen in our UI. But we still want to display the original label and we need to be sure that the existing behaviour hasn’t been broken.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c939a53f3cea106099add5bbd54e4c4/href">https://medium.com/media/1c939a53f3cea106099add5bbd54e4c4/href</a></iframe><p>And lets get the code compiling by updating the view model too:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/81db5778d3bf1224ff802a79d374bbfa/href">https://medium.com/media/81db5778d3bf1224ff802a79d374bbfa/href</a></iframe><p>When we run the test we’ll discover we’ve introduced a bug in the formatting of the output text because we forgot to put a space between the first name and the last name:</p><pre>XCTAssertEqual failed: (“<strong>JohnAppleseed</strong>, 1 Infinite Loop, Cupertino, CA”) is not equal to (“<strong>John Appleseed</strong>, 1 Infinite Loop, Cupertino, CA”) —</pre><p>This is a really basic example, but it shows how writing a unit test first can help us make sure we don’t create bugs when we refactor our code. It’s worth pointing out here that this test would have been much harder to write if the code to generate the name and address string was inside a view controller. It’s a good example of the kind of logic that should live inside a view model object. <a href="https://www.objc.io/issues/13-architecture/mvvm/">MVVM</a> — Model, View, View Model — is a very handy pattern to follow if you have logic that you’d like to unit test. But if you have your logic in a view model and it’s still hard to test, then that indicates your code should be refactored. That could involve extracting the logic to separate objects, or splitting the logic into separate testable functions. A topic for another post.</p><h3>Acknowledgements</h3><p>Adding unit tests for legacy functionality is just one strategy for dealing with modifying legacy code. For details of other strategies and techniques I recommend <a href="https://amzn.com/0131177052">Michael Feather’s book “Working Effectively with Legacy Code.”</a></p><p>While writing this post I used a <a href="https://gist.github.com/iosdevben/3bce3170925ff1b3e82d24e25d5876de">Playground</a> and I learned how to get XCTests to run within the playground, thanks to Stuart Sharp’s post about <a href="http://initwithstyle.net/2015/11/tdd-in-swift-playgrounds/">TDD in Swift Playgrounds</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qtwi6-ZnEe2_i-bdd1ImOA.png" /></figure><p><em>Based in Melbourne, Australia, </em><a href="http://ittybittyapps.com/"><strong><em>Itty Bitty Apps</em></strong></a><em> builds great software on mobile and Mac for clients big and small. It also makes </em><a href="https://revealapp.com/"><strong><em>Reveal</em></strong></a><strong><em> </em></strong><em>— Amazingly powerful runtime view debugging for iOS developers.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c32fd7c3e64e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/itty-bitty-apps/unit-tests-and-working-with-legacy-code-c32fd7c3e64e">Unit Tests and Working with Legacy Code</a> was originally published in <a href="https://medium.com/itty-bitty-apps">Itty Bitty Apps</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>