<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Tools on Stay Frosty</title><link>https://frosty.blog/tags/tools/</link><description>Recent content in Tools on Stay Frosty</description><generator>Hugo -- gohugo.io</generator><language>en-gb</language><copyright>© James Frost</copyright><lastBuildDate>Wed, 10 May 2017 20:49:34 +0000</lastBuildDate><atom:link href="https://frosty.blog/tags/tools/index.xml" rel="self" type="application/rss+xml"/><item><title>Inspecting iOS State Restoration Data</title><link>https://frosty.blog/2017/05/10/inspecting-ios-state-restoration-data/</link><pubDate>Wed, 10 May 2017 20:49:34 +0000</pubDate><guid>https://frosty.blog/2017/05/10/inspecting-ios-state-restoration-data/</guid><description>&lt;p&gt;State preservation and restoration allows iOS apps to save state when they&amp;rsquo;re sent into the background, and restore that state if the app is killed and then relaunched. If you&amp;rsquo;ve ever implemented state restoration yourself, you may have run into a case where it&amp;rsquo;d be helpful to see exactly what state iOS was storing.&lt;/p&gt;
&lt;p&gt;It turns out that Apple actually provides a tool to help you do just this, but it&amp;rsquo;s kind of hidden away and documentation is relatively sparse. Fortunately, it&amp;rsquo;s pretty easy to use. When you run it, it&amp;rsquo;ll output a structured plist showing all of your encoded objects, their restoration identifiers, and restoration class information. Here&amp;rsquo;s a step by step guide.&lt;/p&gt;</description><content:encoded><![CDATA[<p>State preservation and restoration allows iOS apps to save state when they&rsquo;re sent into the background, and restore that state if the app is killed and then relaunched. If you&rsquo;ve ever implemented state restoration yourself, you may have run into a case where it&rsquo;d be helpful to see exactly what state iOS was storing.</p>
<p>It turns out that Apple actually provides a tool to help you do just this, but it&rsquo;s kind of hidden away and documentation is relatively sparse. Fortunately, it&rsquo;s pretty easy to use. When you run it, it&rsquo;ll output a structured plist showing all of your encoded objects, their restoration identifiers, and restoration class information. Here&rsquo;s a step by step guide.</p>
<h3 id="1-download-the-tool">1. Download the tool</h3>
<p>Head over to the Apple &ldquo;<a href="https://developer.apple.com/download/more/">Downloads for Apple Developers</a>&rdquo; site and expand the <strong>restorationArchiveTool for iOS</strong> download. You&rsquo;ll want the <code>restorationArchiveTool.dmg</code> file right at the bottom of the list on the right.</p>
<p>Open the dmg, and drag the <code>restorationArchiveTool</code> binary out to somewhere you can easily access it. I placed mine in my <code>~/bin</code> directory.</p>
<h3 id="2-find-your-apps-library-directory">2. Find your app&rsquo;s Library directory</h3>
<p>Next, you need to know the location of your app&rsquo;s <code>Library</code> directory in the simulator. This is where the restoration data gets saved, which you&rsquo;ll inspect with the archive tool. The easiest way to find this is to add a line to your app delegate&rsquo;s <code>application:didFinishLaunchingWithOptions:</code> (or via a breakpoint). Something like this should do the trick:</p>
<p><strong>Objective-C:</strong></p>





<pre tabindex="0"><code>NSLog(@&#34;Library: %@&#34;, [[[[NSFileManager defaultManager] URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] firstObject] path]);</code></pre><p><strong>Swift:</strong></p>





<pre tabindex="0"><code>print(&#34;Library: \(FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask).first!.path)&#34;)</code></pre><p>The path should get logged out to the console when your app launches. It&rsquo;ll be something like this:</p>





<pre tabindex="0"><code>/Users/bob/Library/Developer/CoreSimulator/Devices/1FF2D964-C615-499E-B1D0-8A7DF7343AE5/data/Containers/Data/Application/D6FE3A2C-9553-4270-8262-A94376EF4E5B/Library</code></pre><h3 id="3-get-some-data">3. Get some data</h3>
<p>This part&rsquo;s simple. Launch the app in the simulator, navigate to the part of the app you&rsquo;re interested in, send the app into the background, and stop the app in Xcode. If you open up the library folder you found in the last step, you&rsquo;ll see a folder named <strong>Saved Application State</strong>. Within that, you&rsquo;ll find a <code>data.data</code> file.</p>
<figure>
  <img src="/images/2017/05/Screen-Shot-2017-05-10-at-21.14.38.png" alt="Screen Shot 2017-05-10 at 21.14.38" loading="lazy">
</figure>
<h3 id="4-run-the-tool">4. Run the tool</h3>
<p>Now you need to run the archive tool and point it at the <code>data.data</code> file you just found. In Terminal, enter the following command, but switch out the location of your <code>restorationArchiveTool</code> binary and your app&rsquo;s <code>data.data</code> as required:</p>





<pre tabindex="0"><code>~/bin/restorationArchiveTool --plist --structured -o output.plist /path/to/your/data/file/data.data</code></pre><p>And you&rsquo;re done! You can then open up the generated plist in Xcode. Amongst other things, you&rsquo;ll see a list of top level objects, keyed by their restoration identifiers. You should notice that the restoration identifiers form a path based upon your view controller hierarchy. You can expand any object to see any extra data it&rsquo;s encoded.</p>
<figure>
  <a href="/images/2017/05/Screen-Shot-2017-05-10-at-20.44.26.png"><img src="/images/2017/05/Screen-Shot-2017-05-10-at-20.44.26-1600.png" alt="Screen Shot 2017-05-10 at 20.44.26" loading="lazy"></a>
</figure>
<p>At the bottom of the file, you&rsquo;ll find a list of restoration classes used by each of the encoded objects.</p>
<figure>
  <a href="/images/2017/05/Screen-Shot-2017-05-10-at-20.44.45.png"><img src="/images/2017/05/Screen-Shot-2017-05-10-at-20.44.45-1600.png" alt="Screen Shot 2017-05-10 at 20.44.45" loading="lazy"></a>
</figure>
<p>If you&rsquo;re having some problems with state restoration, then at the very least being able to see this information can give you some hints about whether your issue is with encoding or decoding. Good luck!</p>
]]></content:encoded></item><item><title>Fixing Xcode's Invisible Cursor</title><link>https://frosty.blog/2016/01/16/fixing-xcodes-invisible-cursor/</link><pubDate>Sat, 16 Jan 2016 09:01:37 +0000</pubDate><guid>https://frosty.blog/2016/01/16/fixing-xcodes-invisible-cursor/</guid><description>&lt;p&gt;When writing code, I generally like to use a dark theme in my IDE or text editor. For Xcode, I really like the &lt;a href="https://github.com/chriskempson/tomorrow-theme/tree/master/Xcode%204"&gt;Tomorrow Night&lt;/a&gt; and &lt;a href="https://github.com/alenofx/seti-xcode-theme"&gt;Seti&lt;/a&gt; themes in particular (both of which can be easily installed using the &lt;a href="http://alcatraz.io"&gt;Alcatraz package manager&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;In Xcode, however, there&amp;rsquo;s a slight problem for dark theme fans:&lt;/p&gt;
&lt;figure&gt;
 &lt;img src="https://frosty.blog/images/2016/02/xcode_beam.png" alt="xcode_beam.png" loading="lazy"&gt;
&lt;/figure&gt;
&lt;p&gt;By default the &amp;lsquo;i-beam&amp;rsquo; mouse cursor in the editor is &lt;em&gt;really&lt;/em&gt; hard to see, particularly on a high resolution monitor. I&amp;rsquo;d often find myself losing it and having to shake the mouse to activate El Capitan&amp;rsquo;s &lt;a href="http://www.imore.com/sites/imore.com/files/styles/larger/public/field/image/2015/09/cursor-gif-small-1.gif?itok=ucjubKwg"&gt;mouse zoom&lt;/a&gt; feature.&lt;/p&gt;</description><content:encoded><![CDATA[<p>When writing code, I generally like to use a dark theme in my IDE or text editor. For Xcode, I really like the <a href="https://github.com/chriskempson/tomorrow-theme/tree/master/Xcode%204">Tomorrow Night</a> and <a href="https://github.com/alenofx/seti-xcode-theme">Seti</a> themes in particular (both of which can be easily installed using the <a href="http://alcatraz.io">Alcatraz package manager</a>).</p>
<p>In Xcode, however, there&rsquo;s a slight problem for dark theme fans:</p>
<figure>
  <img src="/images/2016/02/xcode_beam.png" alt="xcode_beam.png" loading="lazy">
</figure>
<p>By default the &lsquo;i-beam&rsquo; mouse cursor in the editor is <em>really</em> hard to see, particularly on a high resolution monitor. I&rsquo;d often find myself losing it and having to shake the mouse to activate El Capitan&rsquo;s <a href="http://www.imore.com/sites/imore.com/files/styles/larger/public/field/image/2015/09/cursor-gif-small-1.gif?itok=ucjubKwg">mouse zoom</a> feature.</p>
<p>But there&rsquo;s a solution! I noticed that <strong>Terminal.app&rsquo;s</strong> i-beam cursor has a stronger shadow, which makes it easier to see on dark backgrounds. The cursors are just <code>.tiff</code> image files, so it&rsquo;s trivial to steal Terminal&rsquo;s cursor and stick it into Xcode.</p>
<p>If you want to do it manually, you&rsquo;ll need to copy <code>/Applications/Utilities/Terminal.app/Contents/Resources/ShadowedIBeam.tiff</code> over the top of <code>/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Versions/A/Resources/DVTIbeamCursor.tiff</code>. Or you can just run this snippet in Terminal, which will do it for you:</p>





<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">cd</span> /Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Versions/A/Resources<span class="p">;</span> sudo mv DVTIbeamCursor.tiff DVTIbeamCursor.old<span class="p">;</span> sudo cp /Applications/Utilities/Terminal.app/Contents/Resources/ShadowedIBeam.tiff DVTIbeamCursor.tiff</span></span></code></pre></div><p>The change in shadow is actually only slight, but I find it makes a big difference in helping me locate the cursor:</p>
<figure>
  <img src="/images/2016/02/terminal_beam.png" alt="terminal_beam.png" loading="lazy">
</figure>
<p>And here&rsquo;s a before and after:</p>
<figure>
  <img src="/images/2016/02/before_and_after_beams.png" alt="before_and_after_beams.png" loading="lazy">
</figure>
<p><strong>Update:</strong> On Twitter, <a href="http://twitter.com/TwoLivesLeft">@TwoLivesLeft</a> pointed out that iTerm&rsquo;s cursor has even better contrast:</p>
<p><a href="https://twitter.com/TwoLivesLeft/status/695573097408139265">https://twitter.com/TwoLivesLeft/status/695573097408139265</a></p>
<p>**Update 2:**Also on Twitter, <a href="http://twitter.com/GregHeo">GregHeo</a>, there&rsquo;s a super-mega visible cursor available on Github: <a href="https://github.com/egold/better-xcode-ibeam-cursor">https://github.com/egold/better-xcode-ibeam-cursor</a></p>
]]></content:encoded></item></channel></rss>