Loading a view from a XIB

Ever since they where introduced I’ve been a huge fan of using storyboards in Xcode. Storyboards gives you a great overview of the flow in an app and in some cases even replaces the need of a separate mockup tool. But storyboards also have a huge disadvantage; By being stored in a single file it’s practically impossible to have several developers working on the same storyboard file at the same time. It is also rather cumbersome to reuse views and components in other projects when they are embedded in a storyboard file. All of this has made me go back to using single XIB-files again. XIB-files gives you a lot more flexibility and you can have XIB-files for all sorts of UI-components if you like.

But XIBs has their issues to. For example, I think it looks rather messy to load your UI components like this:

In order to getter a little bit cleaner code I packed this functionality up in a category like this:

Then by importing this category and make sure you’ve named your XIB files the same as your classes you can now get a little bit cleaner code.