Cocoa Manifest2015-02-10T08:51:35-08:00http://cocoamanifest.net/Jonathan Pennjonathan@cocoamanifest.netThe Paradigms of SwiftJonathan Penn2014-06-12T23:54:00-07:00http://cocoamanifest.net/linked/2014/06/the-paradigms-of-swift
<p>Rob Napier on why <a href="http://robnapier.net/swift-is-not-functional/">Swift is not a functional language</a>:</p>
<blockquote>
<p>Swift is a multi-paradigm, but it’s not OOP/functional. It’s OOP/generic.
Generic programming is primarily concerned with general purpose algorithms
that can be applied to arbitrary types. It has some similarities with
functional programming, and there are certainly languages that are both
functional and generic, but generic programming doesn’t care if the
algorithms are functions (things that take and return immutable values) or
processes (things that mutate state).</p>
</blockquote>
<p><a rel='permalink' href='http://cocoamanifest.net/linked/2014/06/the-paradigms-of-swift.html'>✦ Permalink</a></p>
New O'Reilly Videos For iOS (with Yours Truly)Jonathan Penn2014-06-08T22:25:00-07:00http://cocoamanifest.net/linked/2014/06/new-o-reilly-videos-for-ios-with-yours-truly
<p>If you’ve ever wanted to peek over the shoulders of <a href="http://twitter.com/kognate">Josh Smith</a> and me to
watch how we build iOS applications, check out these <a href="http://shop.oreilly.com/product/110000628.do?cmp=gplus-na-books-videos-product-dow_creating_awesome_ios_interfaces">brand new videos
published by O’Reilly</a>. We cover a range of stuff from the paper
prototyping phase to how we approach building transitional animations,
debugging, testing, and more.</p>
<p>We are quite proud of how these videos turned out. We had a chance to be among
the first batch of O’Reilly’s new video content initiative. Josh has even gone
on by himself to do a video on Core Data and security (should be out soon).
It’s been an honor and a lot of fun to work with the O’Reilly team. They have a
professional video crew that did all the dirty work with lighting, framing, and
editing. We just brought the content.</p>
<p>If you’re interested in doing videos of your own content with O’Reilly then
<a href="https://twitter.com/amyjollymore">get in touch with Amy Jollymore</a>. They are looking for new authors.</p>
<p><a rel='permalink' href='http://cocoamanifest.net/linked/2014/06/new-o-reilly-videos-for-ios-with-yours-truly.html'>✦ Permalink</a></p>
Unit Testing with SwiftJonathan Penn2014-06-06T10:31:00-07:00http://cocoamanifest.net/linked/2014/06/unit-testing-with-swift
<p>Brad Grzesiak wrote up some of <a href="http://bendyworks.com/unit-testing-in-swift/">his findings while trying to unit test Swift
code</a>. </p>
<p><a rel='permalink' href='http://cocoamanifest.net/linked/2014/06/unit-testing-with-swift.html'>✦ Permalink</a></p>
Where The Metal API Could Be HeadedJonathan Penn2014-06-03T22:27:00-07:00http://cocoamanifest.net/linked/2014/06/where-the-metal-api-could-be-headed
<p>For those who (like me) were curious to know more about the reasoning beind the
new Metal API Apple announced at WWDC 2014, Ryan Smith at AnandTech <a href="http://www.anandtech.com/show/8116/some-thoughts-on-apples-metal-api">describes
why the graphics industry wants to strip away the higher layers like OpenGL and
DirectX for better performance</a>. He also speculates about use beyond
graphics:</p>
<blockquote>
<p>The low-level nature of Metal on the other hand means that it’s a good (or at
least better) fit for GPU computing, as the lack of abstraction for graphics
makes it more capable of handling the workflows and data types of compute
tasks. This is one area in particular where the Metal shader language being
based on a subset of C++11 is a benefit to Apple, as it provides a solid
foundation for writing compute kernels.</p>
</blockquote>
<p><a rel='permalink' href='http://cocoamanifest.net/linked/2014/06/where-the-metal-api-could-be-headed.html'>✦ Permalink</a></p>
✦ Announcing KeyGrip: the Pasteboard Presentation ToolJonathan Penn2014-04-30T16:33:00-07:00http://cocoamanifest.net/articles/2014/04/announcing-keygrip-the-pasteboard-presentation-tool
<p><a href="http://twitter.com/kognate">Josh Smith</a> and I have been busy building a tool to help us tell a story
while live coding in our presentations and workshops. We’ve decided to open
source it and we’re ready to share it with you.</p>
<p>Behold: <a href="https://github.com/rubbercitywizards/keygrip">KeyGrip</a>.</p>
<p><img src="http://cocoamanifest.net/assets/2014/04/keygripdemo.gif" alt="KeyGrip quick screencast" /></p>
<p>A while back Apple wrote a Mac app called Demo Monkey that gave you a list of
things you could click on to put them on the pasteboard. It made presenting
code a little bit easier since you could break up what you wanted to show into
chunks, weave it into a narrative, and paste as you go to demonstrate.</p>
<p>But that required having a window visible on your Mac with a list of clips. And
if you’re like me, you still needed script notes somewhere near by to stay on
track and remember what clip goes where in the flow.</p>
<p>That’s why we wrote KeyGrip. After iterating on a few different ideas, we
settled on a Mac server and a Universal iOS client. Run the client on an iPad
Mini and it shows your presenter notes interspersed with code snippets—all
generated from a <a href="https://daringfireball.net/projects/markdown/">Markdown</a> file. If you tap on any of the code snippets,
it instantly shows up on your Mac’s pasteboard.</p>
<p>The Mac and iOS apps communicate seamlessly over Bonjour. All you have to do is
make sure they have the same string identifier so they can find each other. The
Mac server also live pushes changes to the iOS client while you work on the
Markdown script. You can get into a slick editing workflow where you adjust
your notes and try out your code examples.</p>
<p>Yeah, I’m biased. But I gotta say…this thing is like magic.</p>
<p>You can download a binary of the Mac server right from the <a href="https://github.com/rubbercitywizards/keygrip">README</a>. You can
download the source and build the iOS app to install it on your favorite
device. Enjoy!</p>
<p>Oh, and special thanks to <a href="http://twitter.com/PixelJanitor">Derek Briggs</a> for the icon. He’s got plans to
help us polish up the interface a bit over time, too. :)</p>
✦ UI Screen Shooter - Now Simpler and More Robust Since Xcode 5.1Jonathan Penn2014-03-14T15:03:00-07:00http://cocoamanifest.net/articles/2014/03/ui-screen-shooter-now-simpler-and-more-robust-since-xcode-5-1
<p>The <a href="https://github.com/jonathanpenn/ui-screen-shooter">UI Screen Shooter</a> scripts have been updated for Xcode 5.1! I’m quite
pleased with the results. The <code>instruments</code> command line tool now lets us
specify the simulator device directly from the command line. I’ve cleaned up
the scripts and they are <em>much</em> easier to follow. Kudos to Apple on this! And
thanks to <a href="https://github.com/jonathanpenn/ui-screen-shooter/issues/23">Christoph Koehler’s issue</a> that brought all this to my
attention.</p>
<p>If you’d like more details on what changed, read on.</p>
<h2 id="the-old-way-of-hacking-things">The Old Way of Hacking Things</h2>
<p>You no longer have to force Xcode to pick the iPhone architecture with the
<code>TARGETED_DEVICE_FAMILY</code> configuration parameter. Previously, the <code>instruments</code>
command line tool would not let you pick whether you wanted to run on the iPad
or iPhone simulators. If an app was marked as universal, Instruments would
always launch the app in the iPad simulator. The hack to get around that was to
set the <code>TARGETED_DEVICE_FAMILY</code> to <code>1</code> which would force Xcode to build the
app as iPhone only. Instruments would then oblige and only launch the iPhone
simulator.</p>
<p>In order to get screenshots on both iPad and iPhone, you had to build <em>twice</em>
with different <code>TARGETED_DEVICE_FAMILY</code> settings. It was a real pain, but it
worked.</p>
<p>You also no longer have to muck with the simulator preference files to force
the simulator to launch in a specific language. Previously, I hacked together a
shell script that used <code>PlistBuddy</code> to alter the preference files, forcing the
simulator to think only a specific language and locale was available. But
thanks to a <a href="http://cocoamanifest.net/linked/2014/02/nsuserdefaults-not-just-for-persistent-settings.html">post by Ole Begemann</a> on <code>NSUserDefaults</code>, I realized that I
can force the simulator to pick a locale by just passing special command line
parameters.</p>
<p>And that’s not all! You also no longer need to force the simulator to a specific
device model with AppleScript! Previously (you can see a theme here), I used an
AppleScript that launched the simulator and picked the proper device type from
the Hardware menu. When Instruments next launched, it would use the previous
simulator setting. Again, it worked but it was a horrible hack.</p>
<p><em>Update</em>: Brad Grzesiak <a href="https://twitter.com/listrophy/status/444685900203585536">just pointed out to me</a> that there’s no longer
the need for my <a href="https://github.com/jonathanpenn/ui-screen-shooter/commit/f64875a4f8dfe852a43c417f8e860cf28c925b68">pty/tty</a> hack in the <code>unix_instruments</code> wrapper since the
Instruments command line tool no longer buffers it’s output when piped. We
still need the wrapper script, though, because Instruments doesn’t return a
non-zero status code on JavaScript failure, but hey, I’ll take every
opportunity I can get to remove my workaround code.</p>
<h2 id="the-new-glorious-way">The New, Glorious Way</h2>
<p>All that changed in Xcode 5.1 because Instruments now supports specifying the
simulator hardware type <em>and</em> iOS version all from the command line! To find
out what options you currently have you on your machine, just type the
following:</p>
<pre><code>instruments -w help
</code></pre>
<p>And then you’ll see something like this:</p>
<pre><code>iPhone Retina (3.5-inch) - Simulator - iOS 7.1
iPhone Retina (4-inch) - Simulator - iOS 7.1
iPhone Retina (4-inch 64-bit) - Simulator - iOS 7.1
iPad Retina - Simulator - iOS 7.1
iPad Retina (64-bit) - Simulator - iOS 7.1
...
</code></pre>
<p>Finally! It doesn’t matter what you put after the <code>-w</code> flag. You just need to
pass something invalid and <code>instruments</code> gives you the valid options. Pass one
of these strings in like so to use it:</p>
<pre><code>instruments -w "iPad Retina - Simulator - iOS 7.1" ...
</code></pre>
<p>Note that you <em>need</em> the quotation marks because of the spaces in the full name
of the simulator hardware type and version. Also, the <code>-w</code> flag <em>must</em> come at
the start of the command line, before any other flags. Otherwise you get
strange errors.</p>
<p>Check out <a href="https://github.com/jonathanpenn/ui-screen-shooter">the full screen shooter repository</a> for more details. Use this
as the basis to write your own screen shooting scripts. Enjoy!</p>
Our Sprite Kit Book Now In BetaJonathan Penn2014-03-05T10:47:00-08:00http://cocoamanifest.net/linked/2014/03/our-sprite-kit-book-now-in-beta
<p><a href="http://twitter.com/kognate">Josh Smith</a> and I have been working on a Sprite Kit book with the
Pragmatic Programmers for the past few months. <a href="http://pragprog.com/book/pssprite/build-ios-games-with-sprite-kit">It’s now released in
beta</a>!</p>
<p><a rel='permalink' href='http://cocoamanifest.net/linked/2014/03/our-sprite-kit-book-now-in-beta.html'>✦ Permalink</a></p>
Yes, *that* Brent SimmonsJonathan Penn2014-02-27T08:08:00-08:00http://cocoamanifest.net/linked/2014/02/yes-that-brent-simmons
<p>I’m quite enjoying Brent Simmons’ <a href="http://inessential.com/2014/02/26/more_about_contexts_and_syncing">series of posts on his conversion <em>back</em> to
Core Data</a> from raw SQLite in the <a href="http://vesperapp.co">Vesper</a> app. Yes, <a href="http://inessential.com/2010/02/26/on_switching_away_from_core_data"><em>that</em> Brent
Simmons</a>. In each post he states his latest concerns, asks questions, makes
decisions, and follows up as he gets more information. It’s generated some
<a href="http://www.cimgf.com/2014/02/25/deleting-objects-in-core-data/">heated discussions</a>, yet he reacts graciously. Watching his design
decisions change as he gets real time feedback is a treat. It’s like a case
study for productive dialog.</p>
<p><em>Update</em>: And thus far, he’s decided to <a href="http://inessential.com/2014/03/05/starting_over">abandon Core Data</a> and return to
raw SQLite with <a href="https://github.com/ccgus/fmdb">FMDB</a>.</p>
<p><a rel='permalink' href='http://cocoamanifest.net/linked/2014/02/yes-that-brent-simmons.html'>✦ Permalink</a></p>
NSUserDefaults - Not Just For Persistent SettingsJonathan Penn2014-02-26T10:47:00-08:00http://cocoamanifest.net/linked/2014/02/nsuserdefaults-not-just-for-persistent-settings
<p>Ole Begemann just wrote a <a href="http://oleb.net/blog/2014/02/nsuserdefaults-handling-default-values/">nice article on <code>NSUserDefaults</code></a>. It’s a good
overview for newcomers to the platform, but it also highlighted a feature that I
hadn’t considered before—domains.</p>
<p>Different configuration data can come from, or be stored, in different domains.
What surprised me most was the <code>NSArgumentDomain</code>. It’s a volitile storage
space (won’t be persisted across app runs) and is populated at app launch from
command line parameters. Remember the strange command flag syntax to <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreData/Articles/cdTroubleshooting.html#//apple_ref/doc/uid/TP40002320-SW21">turn on
Core Data’s SQLite debug logs</a>? It sets the values in the
<code>NSArgumentDomain</code> of the app’s <code>NSUserDefaults</code>.</p>
<p><a rel='permalink' href='http://cocoamanifest.net/linked/2014/02/nsuserdefaults-not-just-for-persistent-settings.html'>✦ Permalink</a></p>
Don't Write Off Tinkering In The GarageJonathan Penn2014-02-25T09:23:00-08:00http://cocoamanifest.net/linked/2014/02/don-t-write-off-tinkering-in-the-garage
<p>Andy Arvanitis, of <a href="http://cocoamanifest.net/linked/2012/07/if-objective-c-and-python-had-a-baby.html">eero</a> <a href="http://cocoamanifest.net/linked/2013/07/eero-hits-v2-0.html">language</a> fame, is at it again and
<a href="http://andyarvanitis.com/using-idris-with-objective-c/">experimenting with Idris</a>, a Haskell like language with a simple
interface to C. Which, of course, means he’s experimenting with bridges to
Objective-C classes.</p>
<p>Idris fascinates me because it not only has a flexible syntax, but you can
define your own syntax rules <em>on the fly</em><sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup>. Andy shows off how he builds the
same bracket and parameter list syntax you’re familiar with in Objective-C.
It’s like programming language putty.</p>
<p>I love this kind of stuff. I know, I know, <a href="http://kickingbear.com/blog/archives/412">this adds to the complaint
fodder</a> about the creaking husk of Objective-C. I applaud work like what
Andy is doing precisely because it charges our imagination with what’s
possible—borrowing useful solutions in other arenas to experiment at the
intersection of Objective-C/Cocoa’s history and today. I’m all for what happens
when someone hermits up, thinks hard, and <a href="http://en.wikipedia.org/wiki/Clojure">designs a language with specific
goals</a>. But, don’t write off the tinkering in the garage.</p>
<div class="footnotes">
<ol>
<li id="fn:1">
<p>And you thought Ruby’s metaprogramming possibilities were frightening!<a href="#fnref:1" rel="reference">↩</a></p>
</li>
</ol>
</div>
<p><a rel='permalink' href='http://cocoamanifest.net/linked/2014/02/don-t-write-off-tinkering-in-the-garage.html'>✦ Permalink</a></p>
Apple's Secure Coding GuideJonathan Penn2014-02-24T11:12:00-08:00http://cocoamanifest.net/linked/2014/02/apple-s-secure-coding-guide
<p><a href="https://developer.apple.com/library/ios/documentation/Security/Conceptual/SecureCodingGuide/Introduction.html">Apple’s Secure Coding Guide</a>. Linked <a href="http://cocoamanifest.net/linked/2014/02/security-is-code-formatting.html">non-ironically</a>.</p>
<p><a rel='permalink' href='http://cocoamanifest.net/linked/2014/02/apple-s-secure-coding-guide.html'>✦ Permalink</a></p>
Security Is Code FormattingJonathan Penn2014-02-24T11:02:00-08:00http://cocoamanifest.net/linked/2014/02/security-is-code-formatting
<p>What a weekend. Apple released <a href="http://support.apple.com/kb/HT6147">iOS 7.0.6</a> to plug a hole that let’s an
attacker “capture or modify data in sessions protected by SSL/TLS”. Vague and
ominous.</p>
<p>Then Adam Langley wrote up an <a href="https://www.imperialviolet.org/2014/02/22/applebug.html">excellent summary of the problem</a> after
code spelunking through the open source bits of iOS and OS X. <strong>W. T. F.</strong></p>
<p>It’s all because of a <code>goto</code> statement that skips proper TLS verification under
some circumstances. It was missed because of indentation that made it <em>look</em>
like it was part of the <code>if</code> statement above. But because the <code>if</code> statement
lacked curly braces, only the immediately following statement was covered by the
conditional. The second <code>goto</code> always runs and skips the rest of the critical
verification code. If an attacker knows how to cause this sequence of events,
they have free reign with a <a href="http://en.wikipedia.org/wiki/Man-in-the-middle_attack">man-in-the-middle attack</a>.</p>
<p><hindsight type=”shameless” scope=”20/20”><br />
Check brace-less conditionals and formatting, please. And write tests for
security code wherever possible.<br />
</hindsight></p>
<p>By the way, <a href="http://golang.org/cmd/gofmt/">Golang’s code formatter</a> would have enforced curly braces for
these if statements and reformatted indentation to expose the lone <code>goto</code>
automatically. Compiler enforced formatting rules for the win, eh?</p>
<p>For even more details, read <a href="https://www.cs.columbia.edu/~smb/blog//2014-02/2014-02-23.html">Dave Farber’s write up</a> of the situation.</p>
<p><a rel='permalink' href='http://cocoamanifest.net/linked/2014/02/security-is-code-formatting.html'>✦ Permalink</a></p>
DTrace - Lightning Stolen From The Unix Gods For Use By Mere MortalsJonathan Penn2014-02-12T11:07:00-08:00http://cocoamanifest.net/linked/2014/02/dtrace-lightning-stolen-from-the-unix-gods-for-use-by-mere-mortals
<p>After linking to the <a href="http://cocoamanifest.net/linked/2014/02/strace-tool-of-the-unix-gods.html">enjoyable read on <code>strace</code></a> by Chad Fowler, Mark
Dalrymple <a href="https://twitter.com/borkware/status/432920538877399040">enticed me</a> to point out <code>DTrace</code>, which you might have heard of
as the magic engine running under Apple’s Instruments monitoring and debugging
tool. Personally, I’ve spent more time in Instruments than down in the bowels
of <code>DTrace</code>, but I’ve bookmarked <a href="http://blog.bignerdranch.com/1907-hooked-on-dtrace-part-1/">Mark’s posts as my starting place</a> for
when I need it.</p>
<p><a rel='permalink' href='http://cocoamanifest.net/linked/2014/02/dtrace-lightning-stolen-from-the-unix-gods-for-use-by-mere-mortals.html'>✦ Permalink</a></p>
strace - Tool of The Unix GodsJonathan Penn2014-02-10T10:10:00-08:00http://cocoamanifest.net/linked/2014/02/strace-tool-of-the-unix-gods
<p>Chad Fowler wrote up his experiences <a href="http://chadfowler.com/blog/2014/01/26/the-magic-of-strace/">using <code>strace</code> to debug Lotus Domino
problems</a> back in the day. It’s a great story and a nice introduction to
a useful tool for anyone using a language bolted on top of C and the Unix
subsystems—like, say, Objective-C programmers!</p>
<p><a rel='permalink' href='http://cocoamanifest.net/linked/2014/02/strace-tool-of-the-unix-gods.html'>✦ Permalink</a></p>
Solving The Huge View Controller ProblemJonathan Penn2014-02-05T11:49:00-08:00http://cocoamanifest.net/linked/2014/02/solving-the-huge-view-controller-problem
<p>Brad Grzesiak wrote a <a href="http://bendyworks.com/geekville/articles/2014/2/single-responsibility-principle-ios">thoughtful piece on following the single responsibility
principle when building view controllers in storyboards</a>. His take
challenged me since I had always thought the <a href="http://en.wikipedia.org/wiki/Single_responsibility_principle">single responsibility
principle</a> was just a good guideline for making sure a class doesn’t do
too much <em>right now</em>. But, as Brad points out:</p>
<blockquote>
<p>By focusing on why the class might <em>have to be changed</em>, the <a href="http://en.wikipedia.org/wiki/Single_responsibility_principle">Single
Responsibility Principle</a> allows us to think of how we interact with the code
in the present instead of requiring us to project our minds onto the
software’s future running environment. This, I believe, is an important, and
freeing, distinction.</p>
</blockquote>
<p>In other words, separating out the responsibilities clarifies where we need to
look when requirements change. And the requirements <em>always</em> change. Software
shares much in common with living organisms that must adapt to their
environment. That adaptation is quite messy. The organism could get sick or
sprout cancerous growths. It’s quite different from the process to build a
finished structure, like a bridge, that only changes as it degrades according
to the properties of the materials it was built with.</p>
<p>Brad demonstrates how he tries to minimize those cancerous growths in his
software. It’s good to see more examples of breaking apart the responsibilities
of a view controller into collaborating objects that all live together in a
storyboard scene.</p>
<p><a rel='permalink' href='http://cocoamanifest.net/linked/2014/02/solving-the-huge-view-controller-problem.html'>✦ Permalink</a></p>