Four Things I Learned Making My First Swift App

Check out four things I learned about Swift by shipping my first Swift app! By Greg Heo.

Leave a rating/review
Save for later
Share

Note from Ray: At our company (Razeware), in addition to making written and video tutorials, we release our own apps too – we believe this helps make our material even better.

In this post, one of our newest full-timers will discuss the first app he developed at Razeware, with the goal of getting some practical experience for an upcoming video tutorial series on App Extensions. Enjoy!

My big app project over the summer was Instant Poetry 2, a Swift and iOS 8 complete rewrite of an app Ray wrote a long time ago when he was an indie iOS developer.

This was a huge learning experience for me – not only picking up the intricacies of Swift and iOS 8, but also thinking how best to teach this material in future books and tutorials.

So in the grand tradition of listicles, here are Four Things I Learned Making My First Swift App.

4) Swift Is In Flux

There were huge changes to the language over the summer. I started working on the app around beta 3, and each Xcode release brought syntax changes and Cocoa method signature tweaks.

Insert Rage Face Here!

If you plan to work on an app in Swift, you need to budget time to keep pace with the language.

I think it’s worth it though – it’s important to stay up to date with the latest and greatest, and a good learning experience. Apple has also been good about listening to feedback and bug reports about Swift, so you even have a chance to shape the future of the language.

3) Swift Exposes the Uglier Bits of Cocoa

Are you expecting a nice Swift array of SKProduct objects? No, Cocoa returns an implicitly unwrapped optional array of AnyObject.

Do you think you can pass a nice Swift array of type [NSObject: AnyObject] to that method? No, Cocoa really wants an NSDictionary or things will silently fail.

You can just feel the tension between what Swift wants to do vs the tradeoffs it has to make to fit Cocoa. Looking at Cocoa though a Swift lens isn’t always pretty!

obj-c-swift-cats

The bad news is we’re in a transition. Part of what Apple does in each release is clean up the Swift-Cocoa interface.

The good news is that Apple is very good at transitions. Think about the transitions from PowerPC to Intel, Classic Mac OS to OS X, etc. Some day in the future, Cocoa will “just work” and natively fit in with Swift.

2) Swift Plays Nicely with Objective-C

Really, this is a corollary to the previous points – the reason you notice some Swift oddities is because Swift needs to work with the Objective-C runtime and Objective-C APIs.

obj-c-and-swift-sunset

On the practical side, using Objective-C third-party libraries and extensions (like Facebook Pop) in my Swift app was simple. I simply imported the headers in my bridging header, and it just worked.

If you have a favorite library that’s written in Objective-C or an existing app where you want to try adding in one or two Swift classes, you shouldn’t have any issues.

1) Swift is Enormously Fun

I’ve been enjoying my time with Swift.

The language is expressive. Things like optional chaining and nil coalescing make for shorter code. I’m most surprised at how much I enjoy enums – they really are a win-win that make your code more readable with the added benefit of type checking and exhaustive case checking.

happyrage

As a fan of both Objective-C and Ruby, I feel like Swift is a great mix of those two languages. If you know Objective-C and Cocoa, you’ll have no problem reading Swift code; if you haven’t already, start a simple app in Swift and give it a try!

Bonus Item: Extensions Will Change the World!

Well, the Apple world at least. In iOS 8, Apple introduced app extensions, which allows developers to extend their apps into custom sharing options, notifications, keyboards, and photos.

In Instant Poetry 2, I used a Photo Extension to allow users to add poetry to their images, right within the Photo app. This wouldn’t have been possible before iOS 8!

iOS 8 Photo Extension

It’s great that apps are no longer limited to their own sandbox. It looks like this new open Apple is moving toward apps being able to do more things, from more places.

Even if the upcoming Apple Watch is just an extension of the iPhone’s screen, I can’t wait to see what we’ll be able to do with Watch Kit.

Maybe my next Swift app will be something for the Apple Watch! :]

Where to Go From Here?

I expect the rough edges of Swift will be sanded down in the short term. Before you know it, there will be Swift apps everywhere and Swift projects will outnumber Objective-C ones when you browse GitHub.

But in the here and now of trying to ship apps, it can be a real challenge. I expect that moving a project from Swift 1.0 to Swift 2.0 will be a good amount of work, although not as much as moving from Objective-C to Swift.

But that’s why we love technology, isn’t it? Learning, staying up to date, and working on the latest and greatest in languages and APIs is what keeps me excited.

swift-poem

If you want to check out Instant Poetry 2, you can download it for free on the App Store! I’d love to hear any comments or suggestions you have.

Have you shipped your first Swift app yet? If so, I’d love to hear your experience too. Please join the forum discussion below!

Greg Heo

Contributors

Greg Heo

Author

Over 300 content creators. Join our team.