iOS 8 App Extension Development Tips

Great insight from Tom Harrington on developing iOS 8 app extensions. For developers, Extensions are still very much uncharted territory and Tom breaks down some of the gotchas you'll come across when in Xcode.

Recently I’ve been working on some iOS 8 app extensions, and I’ve run into a few non-obvious details that might come in handy for anyone else in the same situation. Some of the following relates to bugs still in the system, and so will probably only be relevant for a limited time.

Empty UITableViews with DZNEmptyDataSet

One item on my iOS 8 wish list from May was a new UIKit API for empty content views in UITableView. A simple UITableView data source method where you can return a UIView. UITableView would then intelligently display the provided UIView whenever there was no content in the tableView.

But WWDC passed and no such luck. Luckily, DZNEmptyDataSet to the rescue! You can find it here on Github.

It's easy to add to any project using UITableView or UICollectionView and it's being updated regularly.

So this...                                                                                  ...Becomes this!

UITableView with default no content behavior.

UITableView with default no content behavior.

UITableView with an empty content view

UITableView with an empty content view

I've tried many other open source projects and rolled a few techniques myself but none came as close as DZNEmptyDataSet.

Why use an empty content view? Primarily for communicating to the user why the screen is empty and how to add content. It's highly unintuitive, especially on first launch, to display blank rows (as seen in the first image). While a good UI design is self-explanatory and helpful, the default implementation is not.

In the example on the right (taken from Bug Trackr 1.2), I tell the user there isn't any content saved, what they can expect this view to contain, and how to add content. In this case, even though I have an add button at the top right of the screen, I include an "Add Bug" button in the empty content view. Both buttons trigger the same action. This makes it crystal clear that to get new content, you have to tap the add button.

It may seem obvious but, for users launching an app for the very first time, an empty tableView is jarring and confusing.

Apple's default implementation in UITableView is far from ideal and it's interesting that for most of Apple's own apps they implement an empty content view (private API). Until Apple makes their empty content view API public, DZNEmptyDataSet is here to fill the gap.

Coding Nits

But I’ll take the opportunity to point out some things I noticed.

Accessors shouldn’t be of the form getSomething. Drop the get.

#define SOME_CONSTANT 10 isn’t Cocoa-like. Better is static const NSUInteger PBSSomeConstant = 10; (Where PBS is replaced with your prefix.)

If you’re calling something a Handle, it should be an actual Mac memory Handle. And we shouldn’t be using Handles anymore.

All of your class names should have a prefix. All of them.

A sample of Brent Simmons' rules we Cocoa (Touch) developers should all be following. Some great stuff in there.