S Link
Migrating to Swift for iOS Developers
5-day class for iOS developers: Migrate your own Obj-C app to Swift, and explore new iOS 8 features. First class led by Homebrew pro developer Max Howell.
Swift Around the Web
The Point Of Optionals?
"What it took me a while to get was that if we encounter an API or some source of objects that is giving us an optional X, we should probably want to turn it into a non-optional X as soon as we can. We want to push the “deal with the thing not existing” code out as far to the edges of our call graph as we can, and validate things as early as we can, and as close to the source of the objects as we can. This gives us more chance to deal with unexpected situations early before they become bad, and means that the bulk of the code doesn’t have to."
I've also adopted the use of principle on the UI level, using a VIewModel to validate the data before the final object is actually created.
Loopy, Random Ideas for Extending "enum"
I've honestly never thought of extending enums, but of course that is possible in Swift. And after realizing that Swift enums are essentially just more specified classes, it really doesn't seem as "loopy" to extend them as described in this blog post needed.
Which function does Swift call? Part 4: Generics
"Generics are lower down the pecking order. Remember, Swift likes to be as 'specific' as possible, and generics are less specific. Functions with non-generic arguments (even ones that are protocols) are always preferred over generic ones".
@AirspeedVelocity explains how to constrain your generics to make sure they're called. This reminds me of something I heard before about Swift generics - "the more you constrain them, the more you can do with them".
Coding
CMDeviceMotion
Nate Cook points out that the new iPhone gyroscope and accelerometer features sit largely neglected. Then he walks through a cool and super useful use-case for using the CMDeviceMotion framework (scroll down to the gif at the bottom of the article to get excited about CMDeviceMotion!). My guess is that the device motion stuff will be much more important in WATCH development, but it would definitely be interesting to see more iPhone apps use this.
Unit Testing ViewControllers in Swift with iOS 8 and Xcode 6
I've had a few unsuccessful attempts trying to import the Storyboard into my Unit Tests for ViewController testing, and I've given up every time until I found this article. The key is to instantiate your Storyboard from the NSBundle(forClass: self.dynamicType) bundle. Didn't know about self.dynamicType, and still don't fully understand it, but it works...
Draw Gradients with Core Graphics in iOS8 with Swift
I had to add a gradient to a Button a few weeks ago, and was pretty surprised by how hard it is to work with the Core Graphics framework. The code made a lot more sense once I got a designer to explain to me the components of designing a gradient, and of course I played around with the code in a playground, changing the values to really understand what each part of my code did.
Other Cool Stuff
Deadline.
I find this app to be a strangely intriguing use of HealthKit. Can't wait for the WATCH version...
In Case You Missed It
Swift: The Problem with Trailing Closure Syntax
Take a look at this Twitter discussion on how to handle the scenario when you need two closures. Hint: There are some super creative ways in Swift you can avoid this scenario!
Swift: The Curious Case of NSDecimalNumber
It’s crazy how much I’m used to Swift failable initializers already. Just yesterday I was working with NSDecimalNumber, when I encountered the notANumber scenario...
XCode Tip: Autocomplete
In case you haven't noticed, XCode has been pretty buggy with autocomplete functionality for Swift code. Here is a shortcut to help you trigger autocomplete manually.
XCode Tip: Block Select Mode
Sometimes, when you comment something out in XCode, uncommenting using the standard Command + Slash might not work (it just adds another row of // commented out code, instead of uncommenting!). Previously, I just manually removed the // from each line of code. But last week, I learned that there is another, better / cooler solution out there!
Videos
Flat Map
This episode of NSScreencast covers "a horribly named, yet fairly powerful concept called flat map. We'll use this technique to solve the problem we discovered last time dealing with Result<T> and having to use a switch statement everywhere".
WATCH
WatchSpringboard Prototype
Wow! That's all I can say about this. Seriously, watch this demo video. Can't wait for the actual WATCH to come out!
Imagining Productivity Apps for the Apple Watch
In addition to tactic feedback, this is a good reminder that the WATCH will also be able to potentially capture gesture movement and just how powerful that could be.
Swift Code
Swift Thoughts
This week, I've been thinking a lot about KISS and YAGNI as well as SOLID principles as they apply to Swift and iOS. Swift introduces so many extra ways to try to do things (not all of them object-oriented to add to the complexity!), and it's so much fun to try them all, that it's hard to just do the minimum of what is needed for each feature. Still figuring out where to draw the line...