Jekyll2019-05-12T01:58:21+00:00https://blog.mazur.me/feed.xmlblog.mazur.meKarol S. Mazur's blog about iOS software development.Karol S. MazurHow to get Playground Driven Development working with Carthage2019-02-09T00:00:00+00:002019-02-09T00:00:00+00:00https://blog.mazur.me/playground-driven-development-and-carthage<p>I introduced <a href="https://www.pointfree.co/episodes/ep21-playground-driven-development">Playground Driven Development</a> on the last project I worked on. It sped up my development and forced me to write view controllers in a decoupled way. But before I was able to reap the benefits of <abbr title="Playground Driven Development">PDD</abbr> I hit a roadblock: Xcode Playgrounds kept throwing a <code class="highlighter-rouge">Couldn't look up symbols</code> error, because it couldn’t see <a href="https://www.github.com/Carthage/Carthage">Carthage</a>-built dependencies. Here’s how to fix this issue.</p>
<h2 id="identifying-the-problem">Identifying the problem</h2>
<p>Initially I wasn’t sure what the source of my Playgrounds problem was, so I made a <a href="https://github.com/ksm/Habits">sample <abbr title="Playground Driven Development">PDD</abbr> project</a> without Carthage. Next I installed Carthage and added a single dependency<sup id="fnref:1"><a href="#fn:1" class="footnote">1</a></sup>. This reproduced the problem:</p>
<p><img src="/assets/2019-02-09-playground-driven-development-and-carthage-001.png" alt="Screenshot of Xcode Playgrounds with the couldn't lookup symbols error" /></p>
<h2 id="fixing-the-couldnt-look-up-symbols-issue">Fixing the <em>couldn’t look up symbols</em> issue</h2>
<p>I knew Playgrounds were missing some symbols, and I knew this was Carthage related. It became clear that Carthage supplied dependencies weren’t being seen by Playgrounds. What wasn’t so obvious to me is how to fix this issue in a way that wouldn’t require any kind of Xcode project restructuring.</p>
<p>I reached out to the iOS community with the sample project that reproduced the problem, and it turned out that <a href="https://github.com/loganmoseley">Logan Moseley</a> was having the same problem. Within a day Logan figured out the <a href="/assets/2019-02-09-playground-driven-development-and-carthage-logan-fix.png">simple fix</a> I was searching for. Thank you Logan! Here are the steps:</p>
<ol>
<li>Select Xcode → Project Settings → Targets → your main AppFramework target</li>
<li>Click on the Build Phases tab</li>
<li>Add a Copy Files phase</li>
<li>Select Products Directory as the Destination</li>
<li>Drag all Carthage-supplied frameworks in from the project navigator’s frameworks group</li>
<li>Clean and re-build the project, open the project playground and start playing</li>
</ol>
<p>Here’s how the new Copy Files phase should look:</p>
<p><img src="/assets/2019-02-09-playground-driven-development-and-carthage-003.png" alt="Screenshot of Xcode project target settings that fix the Carthage Playground Driven Development issue" /></p>
<p>We’re done. Playground Driven Development with Xcode and Carthage should now work. 💫</p>
<p><img src="/assets/2019-02-09-playground-driven-development-and-carthage-002.png" alt="Screenshot of Xcode Playgrounds working with Carthage after applying the fix" /></p>
<div class="footnotes">
<ol>
<li id="fn:1">
<p>The <a href="https://github.com/ksm/Habits/tree/master">master</a> branch has a self-contained Xcode project with working <abbr title="Playground Driven Development">PDD</abbr>. The <a href="https://github.com/ksm/Habits/tree/carthage">carthage</a> branch installs Carthage and shows the problem (you still have to run <code class="highlighter-rouge">carthage bootstrap</code>). The fix is on <a href="https://github.com/ksm/Habits/tree/carthage-fix">carthage-fix</a>. <a href="#fnref:1" class="reversefootnote">↩</a></p>
</li>
</ol>
</div>Karol S. MazurI introduced Playground Driven Development on the last project I worked on. It sped up my development and forced me to write view controllers in a decoupled way. But before I was able to reap the benefits of PDD I hit a roadblock: Xcode Playgrounds kept throwing a Couldn't look up symbols error, because it couldn’t see Carthage-built dependencies. Here’s how to fix this issue.Tracking dependencies with DEPENDENCIES.md2019-02-03T00:00:00+00:002019-02-03T00:00:00+00:00https://blog.mazur.me/DEPENDENCIES.md<p>A growing list of third-party libraries is something most development projects have to deal with it. On many projects it can be hard to figure out why a certain dependency was added, or whether it still makes sense to keep it. We can track dependencies through a <code class="highlighter-rouge">DEPENDENCIES.md</code> document just like we track changes via a <code class="highlighter-rouge">CHANGELOG.md</code>.</p>
<h2 id="writing-a-dependencies-document">Writing a dependencies document</h2>
<p>There needs to be a good reason for why a dependency gets added to a project. That reason is what we need to write down.</p>
<p>Here’s an example:</p>
<script src="https://gist.github.com/ksm/9b717002c16156b06a695f4d67ed2d7a.js"></script>
<p>The above example shows how we can differentiate between different types of dependencies. As an added benefit we can have a a nice overview of what licenses our dependencies use.</p>
<p>This is a technique I’ve used for a few years on a past project, and it saved a lot of my time when re-evaluating whether some dependencies should be removed.</p>
<h2 id="further-reading">Further reading</h2>
<p>The above pattern is a distant relative of Lightweight Architectural Decisions. What this boils down to is we want to track the reasoning behind our decisions, regardless of whether they affect the architecture or a dependency. This reasoning is also best kept by committing it to the project repository such that it sits right next to our code.</p>
<ul>
<li><a href="https://www.thoughtworks.com/radar/techniques/lightweight-architecture-decision-records">Lightweight Architecture Decision Records</a></li>
<li><a href="http://thinkrelevance.com/blog/2011/11/15/documenting-architecture-decisions">Documenting Architecture Decisions</a></li>
</ul>
<p><strong>Feb 7, 2019 update</strong>: Artsy has their dependency process documented and out in the open. It’s a great read. Of note is how the team at Artsy decides whether a dependency should go through the Artsy RFC process. Thank you to <a href="https://twitter.com/orta">Orta Therox</a> for bringing this to my attention.</p>
<ul>
<li><a href="https://github.com/artsy/README/blob/master/playbooks/dependencies.md">Adding a Dependency Playbook</a></li>
</ul>
<p><strong>Feb 12, 2019 update</strong>: This post got <a href="https://twitter.com/iOSDevWeekly/status/1095397358433640453">featured</a> in a <a href="https://twitter.com/seanallen_dev/status/1095002921253593088">few</a> <a href="https://twitter.com/swiftdevmnts/status/1096490331934216192">places</a>. Thank you!</p>
<ul>
<li><a href="https://iosdevweekly.com/issues/390#1O9CXcY">iOS Dev Weekly #390</a></li>
<li><a href="https://youtu.be/g99P3baA1s0">Swift News #45</a></li>
<li><a href="https://andybargh.com/swiftdevelopments-170/">Swift Developments #170</a></li>
</ul>Karol S. MazurA growing list of third-party libraries is something most development projects have to deal with it. On many projects it can be hard to figure out why a certain dependency was added, or whether it still makes sense to keep it. We can track dependencies through a DEPENDENCIES.md document just like we track changes via a CHANGELOG.md.Hello, World!2019-01-05T00:00:00+00:002019-01-05T00:00:00+00:00https://blog.mazur.me/hello-world<p>I’ve always put off creating a blog, but no more. Hello, World! I imagine this blog will mostly be about software development (for the iOS platform especially, so Swift, Xcode, UIKit, and so on). Then again, who knows - I’m not putting any constraints on this blog, so lets see where this journey takes me.</p>Karol S. MazurI’ve always put off creating a blog, but no more. Hello, World! I imagine this blog will mostly be about software development (for the iOS platform especially, so Swift, Xcode, UIKit, and so on). Then again, who knows - I’m not putting any constraints on this blog, so lets see where this journey takes me.