Joris Kluivers

I like to build software.

NIB Based Table View Cells

With the introduction of Storyboards for iOS and view based table views on OS X it is now possible to fully design table views in Interface Builder. Tables hold one or more prototype views which are returned by your delegate method based on a given identifier.

However designing these prototype views is less than ideal. Editing a small area nested within a table view easily leads to mistakes (and broken auto layout constraints).

Thats why I prefer to have each of my cells in individual NIB files. With the added advantage of being able to reuse the cells between different tables. In this post I take a look at the ways to load table view cells from NIB files, on both OS X and iOS.

Instancetype

The always informational NSHipster points out a new addition to Objective-C in LLVM: instancetype.

Use this type as the return type of a method and the compiler knows the returned object will be similar in type to the class defining the method. This is also know as a related result type.

CALayer Based Button Styling

Hackernews recently had a link on its homepage to an article comparing different ways to customize UIButton. One of the customizations used CALayers to change the look of the button.

Using CALayer is my favourite way to implement UIs. However the implementation in the article was a bit odd, and possibly educating readers wrongly. To show a correct implementation I submitted a pull request with three improvements:

  • Since there was no Quartz drawing going on I removed the use of drawRect:. Layers are initialized in the init... methods.
  • Using inherited methods from UIControl instead of doing event handling by hand.
  • Disabled implicit layer animations to be more in line with the other implementations that didn’t have animations either.

See the diff with my changes of the accepted pull request for more details. The article has also been updated since to reflect my suggested changes.

Uuidgen Snippet

Recently I’ve been copy/pasting UUIDs all over the place for various reasons. Here’s a snippet to generate one and add it to the OS X clipboard for immediate use:

Copy UUID to clipboard
1
uuidgen | tr -d '\n' | pbcopy

The tr -d '\n' makes sure the newline from the uuidgen output is removed.

Do Not Disable Native HTML5 <video> Controls

There is currently no way to fully implement something equally as good as the native controls offered by the OS. And this situation will not improve anytime soon.

It’s hard to create something good. Even implementations by the best teams suffer annoyances like buggy synchronisation of the timeline during playback or after scrubbing. I’ve seen this happen on both desktop and iPad on most sites, including YouTube.

Maybe even worse: some features native controls offer are just not possible to implement using HTML.

  • Fullscreen: No standardised API for this yet. There is the FullScreenAPI by Mozilla (also implemented by Webkit and Opera), but as always IE runs behind the competition.
  • Third party features: Most notably AirPlay on iOS devices. It is not possible to offer HTML controls to offer this functionality. Even if the standard add API’s for this, it will always be years behind whatever device / OS manufacturers have to offer.

Vanilla Javascript

Updated Jan 16th 2013: Added vanilla looping using forEach.

All too often new web projects are started by immediately including a framework like jQuery into the page. This is not out of necessity but more out of convenience over having to write against the javascript DOM API’s. Even a lot of popular javascript tutorials now use jQuery by default resulting in an entire new generation of web developers not knowing about standard javascript API’s.

While jQuery and the likes offer a convenient (but in my opinion ugly) shorthand syntax and shield you away from browser incompatibilities they also add overhead. The minified jQuery library is 32kb and even the simplest functionality will add always be slower than native javascript alternatives. You’ll especially notice this on mobile devices which all have limited memory capacity.

Most modern browsers now all include new HTML5 DOM features that make life easier. Next time ask yourself why you’re actually using a framework, vanilla javascript might all you need.

AirPlay Audio Streaming on Mountain Lion

One of Mountain Lions big features is AirPlay mirroring to send your OS X desktop to a big screen tv. However there is nothing in the press materials on streaming audio only. Something all apps on iOS devices have been able to do for a while now, but was limited to iTunes on OS X Lion and earlier.

Turns out this is perfectly possible on Mountain Lion but the documentation is a bit lacking on the subject. To encourage more applications to adopt AirPlay audio streaming I’ll explain how to add this to your application. (Yes, that’s a hint to SoundCloud and Spotify).

Xcode Build Rule for Markdown Files

In this post I’ll show how to use the Xcode build rules to convert Markdown files to HTML.

Since I started writing this blog using Markdown I’ve grown very fond of it’s clean and simple markup. Instead of being distracted by html the focus is on the text itself. To generate a few pages of content for a new application I’m currently developing I decided to use Markdown instead of writing the html myself.

Using a build rule I convert the Markdown source files to html and wrap them in a template file that contains styling and other page information.

Next Generation Bluetooth 4.0 for iOS / Mac

As of iOS 5 and OS X 10.7 a new framework is available: The CoreBluetooth.framework. This framework enables developers to communicate with a new class of energy efficient Bluetooth devices.

For iOS developers not in the MFi program this is the first time external hardware can be accessed directly from an iPhone, without having to resort to wifi or audio-jack/dock-pin accessories.

No wonder I couldn’t wait to try the Bluetooth Smart heart-rate strap when it finally arrived.