<?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>Dev on Stay Frosty</title><link>https://frosty.blog/tags/dev/</link><description>Recent content in Dev on Stay Frosty</description><generator>Hugo -- gohugo.io</generator><language>en-gb</language><copyright>© James Frost</copyright><lastBuildDate>Sun, 16 May 2021 20:14:50 +0000</lastBuildDate><atom:link href="https://frosty.blog/tags/dev/index.xml" rel="self" type="application/rss+xml"/><item><title>Game Engine Investigations</title><link>https://frosty.blog/2021/05/16/game-engine-investigations/</link><pubDate>Sun, 16 May 2021 20:14:50 +0000</pubDate><guid>https://frosty.blog/2021/05/16/game-engine-investigations/</guid><description>&lt;p&gt;I’ve always been interested in game development. Some of the first code I ever wrote was typing BASIC game listings out of books into my BBC Micro and modifying them to fit my own ideas. Then came Windows 3.1 and countless hours noodling around with &lt;a href="https://youtu.be/LUTpumYboDs"&gt;Klik N Play&lt;/a&gt;, followed by DarkBASIC on Windows 95 or 98.&lt;/p&gt;
&lt;p&gt;Ten years ago I entered the popular &lt;a href="https://ldjam.com"&gt;Ludum Dare&lt;/a&gt; game jam (creating a game in just 48 or 72 hours). I made a tiny Indiana Jones-esque temple escape game called &lt;a href="https://web.archive.org/web/20210117135329/http://ludumdare.com/compo/ludum-dare-21/"&gt;Daring Do&lt;/a&gt;, which unfortunately isn’t playable today as I used ActionScript and Flash as my technologies of choice and we all know how that ended up. Nonetheless, I ranked #16 out of 90 entries which I don’t think was too bad as my first ‘proper’ effect.&lt;/p&gt;</description><content:encoded><![CDATA[<p>I’ve always been interested in game development. Some of the first code I ever wrote was typing BASIC game listings out of books into my BBC Micro and modifying them to fit my own ideas. Then came Windows 3.1 and countless hours noodling around with <a href="https://youtu.be/LUTpumYboDs">Klik N Play</a>, followed by DarkBASIC on Windows 95 or 98.</p>
<p>Ten years ago I entered the popular <a href="https://ldjam.com">Ludum Dare</a> game jam (creating a game in just 48 or 72 hours). I made a tiny Indiana Jones-esque temple escape game called <a href="https://web.archive.org/web/20210117135329/http://ludumdare.com/compo/ludum-dare-21/">Daring Do</a>, which unfortunately isn’t playable today as I used ActionScript and Flash as my technologies of choice and we all know how that ended up. Nonetheless, I ranked #16 out of 90 entries which I don’t think was too bad as my first ‘proper’ effect.</p>
<p>Recently I’ve wanted to get back into doing some game dev as a hobby. I’m only really interested in 2D right now as it’s just where I have more interest. I’ve dabbled with Unity a couple of times in the past but I’ve never built anything of much substance, so I’ve decided to spend a couple of weeks getting to know what’s possible with some of the most popular game engines out there today:</p>
<ul>
<li><a href="https://unity.com">Unity</a></li>
<li><a href="https://godotengine.org">Godot</a></li>
<li><a href="https://www.yoyogames.com/en/gamemaker">GameMaker Studio 2</a></li>
<li>Possibly a <a href="https://haxe.org">Haxe</a>-based framework such as <a href="https://haxeflixel.com">HaxeFlixel</a> or <a href="https://heaps.io">Heaps</a></li>
</ul>
<p>I’m planning to take up to a week getting to know the basics of each engine, then build a very small 2D platformer – which can literally just be one or two screens. At the least I’d like to get an understanding of:</p>
<ul>
<li>How good their 2D support is (and in particular pixel art support)</li>
<li>Creating a basic character controller</li>
<li>Importing assets, creating tilemaps, and animating sprites</li>
<li>Scripting and communicating between different components</li>
<li>Support for effects like 2D lighting, shaders, and particle effects</li>
</ul>
<p>This first week I’ve been looking at Godot, and I’ve really been loving it so far. More soon!</p>
]]></content:encoded></item><item><title>WWDC 2016 Developer Tidbits</title><link>https://frosty.blog/2016/06/14/wwdc-2016-developer-tidbits/</link><pubDate>Tue, 14 Jun 2016 14:06:55 +0000</pubDate><guid>https://frosty.blog/2016/06/14/wwdc-2016-developer-tidbits/</guid><description>&lt;p&gt;There were some nice announcements from Apple at WWDC yesterday, including a revamped lock screen and notifications for iOS, SiriKit, and a lot of iMessage integration. Whilst scouring the newly-released developer documentation I&amp;rsquo;ve come across a lot of interesting tidbits that aren&amp;rsquo;t headline features on their own, so I thought I&amp;rsquo;d collect them here in case they&amp;rsquo;re of use to anyone else. In no particular order:&lt;/p&gt;
&lt;h3 id="xcode"&gt;Xcode&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Some nice improvements to Interface Builder. You can now edit your UI at any zoom level (FINALLY)! The UI for customizing layouts for different device traits has also been revamped, and looks really good.&lt;/li&gt;
&lt;li&gt;Image and colour literals are now supported in Swift code, including code completion for images that&amp;rsquo;re in your asset catalog. Simply start typing either &lt;code&gt;color&lt;/code&gt; or &lt;code&gt;UIImage&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;There&amp;rsquo;s a new monospaced code font in Xcode: &lt;code&gt;SF Mono&lt;/code&gt; that seems to match up with the WWDC promo material this year.&lt;/li&gt;
&lt;li&gt;The simulator features a special version of the Messages app which allows you to see both halves of a conversation between two users. Very useful for testing all the iMessage newness.&lt;/li&gt;
&lt;li&gt;Xcode 8 supports both Swift 2.3 and Swift 3. If you choose Swift 2.3 for a project, there&amp;rsquo;s a new build setting that gets set to Yes: &amp;ldquo;Use Legacy Swift Language Version&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;The new memory debugger looks incredible. You can visualize the current object graph, and it can help identify memory leaks / retain cycles.&lt;/li&gt;
&lt;li&gt;Xcode now highlights the active line when editing.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="foundation"&gt;Foundation&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;There&amp;rsquo;s now &lt;a href="https://developer.apple.com/reference/foundation/nsdateinterval"&gt;&lt;code&gt;NSDateInterval&lt;/code&gt;&lt;/a&gt; for counting the duration of a time interval, checking whether a date exists in a range, and comparing intervals.&lt;/li&gt;
&lt;li&gt;FINALLY an &lt;a href="https://developer.apple.com/reference/foundation/nsiso8601dateformatter"&gt;ISO 8601 date formatter&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;NSPersonNameComponentsFormatter&lt;/code&gt; has a new &lt;a href="https://developer.apple.com/reference/foundation/nspersonnamecomponentsformatter/1642979-personnamecomponentsfromstring"&gt;&lt;code&gt;personNameComponentsFromString:&lt;/code&gt;&lt;/a&gt; method that can parse out the individual components of a person&amp;rsquo;s name.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="notifications"&gt;Notifications&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;a href="https://developer.apple.com/reference/usernotificationsui"&gt;User Notifications UI&lt;/a&gt; framework lets you customize the appearance of local and remote notifications when they appear on the user’s device.&lt;/li&gt;
&lt;li&gt;You can also intercept push notifications (through &lt;a href="https://developer.apple.com/reference/usernotifications"&gt;&lt;code&gt;UserNotifications.framework&lt;/code&gt;&lt;/a&gt;) and handle them before they alert the user. For example, you could download a video and &lt;em&gt;then&lt;/em&gt; tell the user it&amp;rsquo;s ready.&lt;/li&gt;
&lt;li&gt;Rich notifications are currently only optimized for 3D Touch, and they&amp;rsquo;ll be providing access to functionality for users of other iPhone models / iPad at a later date.&lt;/li&gt;
&lt;li&gt;A lot of the existing remote and local notification methods on &lt;code&gt;UIApplication&lt;/code&gt; (as well as &lt;code&gt;UILocalNotification&lt;/code&gt; itself) are now deprecated in favour of the &lt;a href="https://developer.apple.com/reference/usernotifications"&gt;&lt;code&gt;UserNotifications&lt;/code&gt;&lt;/a&gt; framework.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="uikit"&gt;UIKit&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;There&amp;rsquo;s a load of &lt;a href="https://developer.apple.com/reference/uikit/uiviewanimating"&gt;new animation APIs&lt;/a&gt;: &amp;ldquo;New object-based, fully interactive and interruptible animation support that lets you retain control of your animations and link them with gesture-based interactions.&amp;rdquo;&lt;/li&gt;
&lt;li&gt;The refresh control is now supported in all scroll views and scrollview subclasses thanks to &lt;a href="https://developer.apple.com/reference/uikit/uirefreshcontrolhosting"&gt;&lt;code&gt;UIRefreshControlHosting&lt;/code&gt;&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Collectionviews and tableviews support prefetching of cells to improve scrolling (&lt;a href="https://developer.apple.com/reference/uikit/uicollectionviewdatasourceprefetching"&gt;&lt;code&gt;UICollectionViewDataSourcePrefetching&lt;/code&gt;&lt;/a&gt; and &lt;a href="https://developer.apple.com/reference/uikit/uitableview/1771763-prefetchdatasource"&gt;&lt;code&gt;UITableViewDataSourcePrefetching&lt;/code&gt;&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;It looks like you can now provide your own previewing UI for 3D Touch: &lt;a href="https://developer.apple.com/reference/uikit/uipreviewinteraction"&gt;&lt;code&gt;UIPreviewInteraction&lt;/code&gt;&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;There are new UIVisualEffectView &lt;a href="https://developer.apple.com/reference/uikit/uiblureffectstyle"&gt;blur types&lt;/a&gt;: prominent and regular.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="core-data"&gt;Core Data&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.apple.com/reference/coredata/nspersistentcontainer"&gt;&lt;code&gt;NSPersistentContainer&lt;/code&gt;&lt;/a&gt; looks like it might replace the simple &lt;code&gt;CoreDataStack&lt;/code&gt; class I&amp;rsquo;d add to most new projects. It encapsulates the whole core data stack, and has convenience methods for creating new background contexts and performing background tasks.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.apple.com/reference/coredata/nsmanagedobject"&gt;&lt;code&gt;NSManagedObject&lt;/code&gt;&lt;/a&gt; gets a few new methods – &lt;code&gt;init(context:)&lt;/code&gt;, &lt;code&gt;fetchRequest()&lt;/code&gt;, &lt;code&gt;entity()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Xcode should be able to automatically generate classes for Core Data entities, but I&amp;rsquo;ve been unable to get this to work so far.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;NSManagedObjectContext&lt;/code&gt; now has an &lt;a href="https://developer.apple.com/reference/coredata/nsmanagedobjectcontext/1845237-automaticallymergeschangesfrompa"&gt;&lt;code&gt;automaticallyMergesChangesFromParent&lt;/code&gt;&lt;/a&gt; property to do the &lt;code&gt;NSManagedObjectContextDidSaveNotification&lt;/code&gt; observation and merging automatically.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="swift-playgrounds"&gt;Swift Playgrounds&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;On iPad, &lt;code&gt;XCPlayground&lt;/code&gt; is replaced by &lt;code&gt;PlaygroundSupport&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;You can record videos of coding sessions right inside the app (in the Share menu).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="watchos"&gt;watchOS&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Glances have gone completely in watchOS 3. Your app should now display and update glanceable information when the user has it in their Dock.&lt;/li&gt;
&lt;li&gt;If the user has your complication on their watch face, your app will be kept in a ready-to-launch state.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.apple.com/reference/watchkit/wkcrownsequencer"&gt;&lt;code&gt;WKCrownSequencer&lt;/code&gt;&lt;/a&gt; lets you directly access information about the crown&amp;rsquo;s state – whether it&amp;rsquo;s rotating, how fast, and when it&amp;rsquo;s stopped.&lt;/li&gt;
&lt;li&gt;SpriteKit and SceneKit on the watch is cray-cray. The State of the Union contains a cool demo where a notification on the watch contains an animated 3D SceneKit scene.&lt;/li&gt;
&lt;li&gt;You can now access information about the watch&amp;rsquo;s orientation, crown position, wrist location, etc in &lt;a href="https://developer.apple.com/reference/watchkit/wkinterfacedevice"&gt;&lt;code&gt;WKInterfaceDevice&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;If you&amp;rsquo;re using a watch app, whenever you lower and raise your wrist, you&amp;rsquo;ll get taken right back into the app, for up to 8 minutes.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="sirikit"&gt;SiriKit&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;SiriKit is limited to only certain domains:&lt;/li&gt;
&lt;li&gt;Audio or video calling&lt;/li&gt;
&lt;li&gt;Messaging&lt;/li&gt;
&lt;li&gt;Sending or receiving payments&lt;/li&gt;
&lt;li&gt;Searching photos&lt;/li&gt;
&lt;li&gt;Booking a ride&lt;/li&gt;
&lt;li&gt;Managing workouts&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="misc"&gt;Misc&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;If you&amp;rsquo;ve indexed content for your app with Core Spotlight, you can now search it programmatically in-app using &lt;a href="https://developer.apple.com/reference/corespotlight/cssearchquery"&gt;&lt;code&gt;CSSearchQuery&lt;/code&gt;&lt;/a&gt;. A user can also continue a Spotlight search &lt;a href="https://developer.apple.com/library/prerelease/content/releasenotes/General/WhatsNewIniOS/Articles/iOS10.html#//apple_ref/doc/uid/TP40017084-DontLinkElementID_6"&gt;inside your app&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Speech recognition is now possible, through the &lt;a href="https://developer.apple.com/reference/speech"&gt;Speech framework&lt;/a&gt; and &lt;code&gt;SFSpeechRecognizer&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;You can set an &lt;a href="https://developer.apple.com/reference/uikit/uipasteboard"&gt;expiry or exclusions for pasteboard data&lt;/a&gt; for the new universal clipboard.&lt;/li&gt;
&lt;li&gt;iOS 10 drops support for the iPhone 4S, iPad Mini, iPads 2 and 3, and the 5th generation iPod touch.&lt;/li&gt;
&lt;/ul&gt;</description><content:encoded><![CDATA[<p>There were some nice announcements from Apple at WWDC yesterday, including a revamped lock screen and notifications for iOS, SiriKit, and a lot of iMessage integration. Whilst scouring the newly-released developer documentation I&rsquo;ve come across a lot of interesting tidbits that aren&rsquo;t headline features on their own, so I thought I&rsquo;d collect them here in case they&rsquo;re of use to anyone else. In no particular order:</p>
<h3 id="xcode">Xcode</h3>
<ul>
<li>Some nice improvements to Interface Builder. You can now edit your UI at any zoom level (FINALLY)! The UI for customizing layouts for different device traits has also been revamped, and looks really good.</li>
<li>Image and colour literals are now supported in Swift code, including code completion for images that&rsquo;re in your asset catalog. Simply start typing either <code>color</code> or <code>UIImage</code>.</li>
<li>There&rsquo;s a new monospaced code font in Xcode: <code>SF Mono</code> that seems to match up with the WWDC promo material this year.</li>
<li>The simulator features a special version of the Messages app which allows you to see both halves of a conversation between two users. Very useful for testing all the iMessage newness.</li>
<li>Xcode 8 supports both Swift 2.3 and Swift 3. If you choose Swift 2.3 for a project, there&rsquo;s a new build setting that gets set to Yes: &ldquo;Use Legacy Swift Language Version&rdquo;.</li>
<li>The new memory debugger looks incredible. You can visualize the current object graph, and it can help identify memory leaks / retain cycles.</li>
<li>Xcode now highlights the active line when editing.</li>
</ul>
<h3 id="foundation">Foundation</h3>
<ul>
<li>There&rsquo;s now <a href="https://developer.apple.com/reference/foundation/nsdateinterval"><code>NSDateInterval</code></a> for counting the duration of a time interval, checking whether a date exists in a range, and comparing intervals.</li>
<li>FINALLY an <a href="https://developer.apple.com/reference/foundation/nsiso8601dateformatter">ISO 8601 date formatter</a>.</li>
<li><code>NSPersonNameComponentsFormatter</code> has a new <a href="https://developer.apple.com/reference/foundation/nspersonnamecomponentsformatter/1642979-personnamecomponentsfromstring"><code>personNameComponentsFromString:</code></a> method that can parse out the individual components of a person&rsquo;s name.</li>
</ul>
<h3 id="notifications">Notifications</h3>
<ul>
<li>The <a href="https://developer.apple.com/reference/usernotificationsui">User Notifications UI</a> framework lets you customize the appearance of local and remote notifications when they appear on the user’s device.</li>
<li>You can also intercept push notifications (through <a href="https://developer.apple.com/reference/usernotifications"><code>UserNotifications.framework</code></a>) and handle them before they alert the user. For example, you could download a video and <em>then</em> tell the user it&rsquo;s ready.</li>
<li>Rich notifications are currently only optimized for 3D Touch, and they&rsquo;ll be providing access to functionality for users of other iPhone models / iPad at a later date.</li>
<li>A lot of the existing remote and local notification methods on <code>UIApplication</code> (as well as <code>UILocalNotification</code> itself) are now deprecated in favour of the <a href="https://developer.apple.com/reference/usernotifications"><code>UserNotifications</code></a> framework.</li>
</ul>
<h3 id="uikit">UIKit</h3>
<ul>
<li>There&rsquo;s a load of <a href="https://developer.apple.com/reference/uikit/uiviewanimating">new animation APIs</a>: &ldquo;New object-based, fully interactive and interruptible animation support that lets you retain control of your animations and link them with gesture-based interactions.&rdquo;</li>
<li>The refresh control is now supported in all scroll views and scrollview subclasses thanks to <a href="https://developer.apple.com/reference/uikit/uirefreshcontrolhosting"><code>UIRefreshControlHosting</code></a>.</li>
<li>Collectionviews and tableviews support prefetching of cells to improve scrolling (<a href="https://developer.apple.com/reference/uikit/uicollectionviewdatasourceprefetching"><code>UICollectionViewDataSourcePrefetching</code></a> and <a href="https://developer.apple.com/reference/uikit/uitableview/1771763-prefetchdatasource"><code>UITableViewDataSourcePrefetching</code></a>)</li>
<li>It looks like you can now provide your own previewing UI for 3D Touch: <a href="https://developer.apple.com/reference/uikit/uipreviewinteraction"><code>UIPreviewInteraction</code></a>.</li>
<li>There are new UIVisualEffectView <a href="https://developer.apple.com/reference/uikit/uiblureffectstyle">blur types</a>: prominent and regular.</li>
</ul>
<h3 id="core-data">Core Data</h3>
<ul>
<li><a href="https://developer.apple.com/reference/coredata/nspersistentcontainer"><code>NSPersistentContainer</code></a> looks like it might replace the simple <code>CoreDataStack</code> class I&rsquo;d add to most new projects. It encapsulates the whole core data stack, and has convenience methods for creating new background contexts and performing background tasks.</li>
<li><a href="https://developer.apple.com/reference/coredata/nsmanagedobject"><code>NSManagedObject</code></a> gets a few new methods – <code>init(context:)</code>, <code>fetchRequest()</code>, <code>entity()</code>.</li>
<li>Xcode should be able to automatically generate classes for Core Data entities, but I&rsquo;ve been unable to get this to work so far.</li>
<li><code>NSManagedObjectContext</code> now has an <a href="https://developer.apple.com/reference/coredata/nsmanagedobjectcontext/1845237-automaticallymergeschangesfrompa"><code>automaticallyMergesChangesFromParent</code></a> property to do the <code>NSManagedObjectContextDidSaveNotification</code> observation and merging automatically.</li>
</ul>
<h3 id="swift-playgrounds">Swift Playgrounds</h3>
<ul>
<li>On iPad, <code>XCPlayground</code> is replaced by <code>PlaygroundSupport</code>.</li>
<li>You can record videos of coding sessions right inside the app (in the Share menu).</li>
</ul>
<h3 id="watchos">watchOS</h3>
<ul>
<li>Glances have gone completely in watchOS 3. Your app should now display and update glanceable information when the user has it in their Dock.</li>
<li>If the user has your complication on their watch face, your app will be kept in a ready-to-launch state.</li>
<li><a href="https://developer.apple.com/reference/watchkit/wkcrownsequencer"><code>WKCrownSequencer</code></a> lets you directly access information about the crown&rsquo;s state – whether it&rsquo;s rotating, how fast, and when it&rsquo;s stopped.</li>
<li>SpriteKit and SceneKit on the watch is cray-cray. The State of the Union contains a cool demo where a notification on the watch contains an animated 3D SceneKit scene.</li>
<li>You can now access information about the watch&rsquo;s orientation, crown position, wrist location, etc in <a href="https://developer.apple.com/reference/watchkit/wkinterfacedevice"><code>WKInterfaceDevice</code></a></li>
<li>If you&rsquo;re using a watch app, whenever you lower and raise your wrist, you&rsquo;ll get taken right back into the app, for up to 8 minutes.</li>
</ul>
<h3 id="sirikit">SiriKit</h3>
<ul>
<li>SiriKit is limited to only certain domains:</li>
<li>Audio or video calling</li>
<li>Messaging</li>
<li>Sending or receiving payments</li>
<li>Searching photos</li>
<li>Booking a ride</li>
<li>Managing workouts</li>
</ul>
<h3 id="misc">Misc</h3>
<ul>
<li>If you&rsquo;ve indexed content for your app with Core Spotlight, you can now search it programmatically in-app using <a href="https://developer.apple.com/reference/corespotlight/cssearchquery"><code>CSSearchQuery</code></a>. A user can also continue a Spotlight search <a href="https://developer.apple.com/library/prerelease/content/releasenotes/General/WhatsNewIniOS/Articles/iOS10.html#//apple_ref/doc/uid/TP40017084-DontLinkElementID_6">inside your app</a>.</li>
<li>Speech recognition is now possible, through the <a href="https://developer.apple.com/reference/speech">Speech framework</a> and <code>SFSpeechRecognizer</code>.</li>
<li>You can set an <a href="https://developer.apple.com/reference/uikit/uipasteboard">expiry or exclusions for pasteboard data</a> for the new universal clipboard.</li>
<li>iOS 10 drops support for the iPhone 4S, iPad Mini, iPads 2 and 3, and the 5th generation iPod touch.</li>
</ul>
]]></content:encoded></item><item><title>Two Nifty Swift Loop Tricks</title><link>https://frosty.blog/2016/02/06/two-nifty-swift-loop-tricks/</link><pubDate>Sat, 06 Feb 2016 19:49:56 +0000</pubDate><guid>https://frosty.blog/2016/02/06/two-nifty-swift-loop-tricks/</guid><description>&lt;p&gt;This week, I learnt two things about Swift that I&amp;rsquo;d never come across before. Both involve loops.&lt;/p&gt;
&lt;p&gt;The first, via &lt;a href="http://ericasadun.com/2016/01/15/3-simple-for-in-iteration-tricks/"&gt;Erica Sadun&lt;/a&gt;: you can use &lt;code&gt;case let&lt;/code&gt; in a &lt;code&gt;for&lt;/code&gt; loop to conditionally bind optionals or cast items. Here&amp;rsquo;s the optional binding example from Erica&amp;rsquo;s post:&lt;/p&gt;





&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-swift" data-lang="swift"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;?]&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;&amp;#34;Hello&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;&amp;#34;World&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;item&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="bp"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Check out the full post, &lt;a href="http://ericasadun.com/2016/01/15/3-simple-for-in-iteration-tricks/"&gt;3 simple for-in iteration tricks&lt;/a&gt; for some other neat tricks.&lt;/p&gt;
&lt;p&gt;Secondly, from &lt;a href="http://krakendev.io/blog/hipster-swift#loop-labels"&gt;this post&lt;/a&gt; at KrakenDev: you can &lt;strong&gt;label loops&lt;/strong&gt; in Swift! Here&amp;rsquo;s an example:&lt;/p&gt;</description><content:encoded><![CDATA[<p>This week, I learnt two things about Swift that I&rsquo;d never come across before. Both involve loops.</p>
<p>The first, via <a href="http://ericasadun.com/2016/01/15/3-simple-for-in-iteration-tricks/">Erica Sadun</a>: you can use <code>case let</code> in a <code>for</code> loop to conditionally bind optionals or cast items. Here&rsquo;s the optional binding example from Erica&rsquo;s post:</p>





<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-swift" data-lang="swift"><span class="line"><span class="cl"><span class="kd">let</span> <span class="nv">items</span><span class="p">:</span> <span class="p">[</span><span class="nb">String</span><span class="p">?]</span> <span class="p">=</span> <span class="p">[</span><span class="kc">nil</span><span class="p">,</span> <span class="kc">nil</span><span class="p">,</span> <span class="s">&#34;Hello&#34;</span><span class="p">,</span> <span class="kc">nil</span><span class="p">,</span> <span class="s">&#34;World&#34;</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"><span class="k">for</span> <span class="k">case</span> <span class="kd">let</span> <span class="nv">item</span><span class="p">?</span> <span class="k">in</span> <span class="n">items</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="bp">print</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span></span></span></code></pre></div><p>Check out the full post, <a href="http://ericasadun.com/2016/01/15/3-simple-for-in-iteration-tricks/">3 simple for-in iteration tricks</a> for some other neat tricks.</p>
<p>Secondly, from <a href="http://krakendev.io/blog/hipster-swift#loop-labels">this post</a> at KrakenDev: you can <strong>label loops</strong> in Swift! Here&rsquo;s an example:</p>





<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-swift" data-lang="swift"><span class="line"><span class="cl"><span class="n">sectionLoop</span><span class="p">:</span> <span class="k">for</span> <span class="n">section</span> <span class="k">in</span> <span class="n">sections</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="n">rowLoop</span><span class="p">:</span> <span class="k">for</span> <span class="n">row</span> <span class="k">in</span> <span class="n">rows</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="k">if</span> <span class="n">row</span><span class="p">.</span><span class="n">isMagical</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">            <span class="k">break</span> <span class="n">sectionLoop</span>
</span></span><span class="line"><span class="cl">        <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span></span></span></code></pre></div><p>Who knew?! There are a bunch more useful tips in the full post, <a href="http://krakendev.io/blog/hipster-swift">Hipster Swift</a>, including descriptions of what <code>@noescape</code> and <code>@autoclosure</code> actually do.</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>