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.

Unity: Start with selected scene

Sometimes when you test your code in Unity you really need to start from a specific scene. There is no way (that I know of) to get Unity to do this for you, but since it’s really simple to extend the editor with your own code I wrote a simple script that saves the current scene and loads a menu scene before running. When you’re done testing, you run the same method again and your last scene will be loaded for you.

Thank you, Unity for making my life so easy!

Which way is up?

We have all been there sometime. You wake up and have absolutly no clue where you are or even which way is up. If you’re an app this happens all the time. But here’s a simple cure;

Right tool for the job

It always strike me how much easier life gets when you use the right tools for the job. I mean try mowing the lawn using a snow thrower, it’s just no fun! (Not that mowing the lawn is all that fun even if you do use the correct tool, but it’s nevertheless easier)

Ferr2D

Using the right tools also helps when developing games. I recently learned how to use the game development IDE Unity and I really love it. It really feels like Unity is built not only for game developers but also by game developers. They really know how to make the development process run smoothly.

In my opinion the biggest advantage is the built in Asset Store and more specific the never ending collection of plugins to extend the editor with new features. Take level building for example. Right now I’m working on a rather simple plattform game. In my first designs I used tiled maps, a well tested technique where you build the level by piecing together different shaped tiles. It’s a tedious work and even if you have a lot of tiles you can’t get all the shapes you’d like. But then I found the Ferr2D plugin and suddenly I saw the light! In Ferr2D you first setup the materials to be used for the top, bottom, left and right edges and the filling texture. Then you just creates meshes in what ever form you like and the Ferr2D plugin makes sure it looks good! Don’t get me wrong, creating a level still takes time. But it’s much easier and it’s so much more fun using the right tools!

Dead Meat

When you have played Magic: The Gathering for some time you’ll notice that the box of spare cards is constantly growing. This box is the home for all those homeless cards that you got in booster packs (or from other sources) and that just doesn’t fit in one of your current decks. It might be because the theme doesn’t fit or because you lack some cards to make a certain mechanism tick.

But then, when the rain is pouring down outside and you have some time to spare, you can open up the box, sort your cards in nice piles and then build a couple of really fun casual game decks and play them against one another. Who knows, maybe you’ll even find some new favourites among your forgotten cards?

Here’s a deck from this weekends casual games.

Dead Meat
Creatures (19)
2  Tenacious Dead
2  Child of Night
2  Corpse Hauler
1  Gnawing Zombie
2  Gutter Skulk
2  Blood Bairn
1  Dead Reveler
1  Lifebane Zombie
1  Undead Minotaur
2  Accursed Spirit
1  Liliana’s Reaver
2  Sengir Vampire

Lands (24)
8  Forest
1  Radiant Fountain
15  Swamp

Other spells (17)
1  Caravan Vigil
1  Fog
2  Giant Growth
2  Prey Upon
2  Vile Rebirth
1  Altar’s Reap
1  Naturalize
1  Staff of the Death Magus
2  Trollhide
1  Launch Party
1  Midnight Recovery
1  Well of Lost Dreams
1  Creeping Renaissance

Properties in a Category

One of the many things I like with Objective-C is the possibility to extend any class without having to write a proper extension class that inherits from the original. The technique is called categories and what you is that you specify one or more new methods to be a part of a given class.

Below is an example of how to extend a standard NSString object with a new custom method that checks if a certain string is a part of the NSString.

To use the above category you simply import the NSString+Contains.h in your source code after that you can use the new method on all NSString objects. Great! But what if you also want to add a property? The category mechanism does not support properties but where there is a will, there is a way.

By declaring a property and then add your own getter and setter methods you can use the C-method objc_setAssociatedObject to connect and retrieve data to an object. Let me show you; In the following example I’ll create a category that will let you store any Objective-C object in a property called customData in a NSString object.

In many cases the best solution is to create a new class that extends another class to accomplish this, but for some situations this proves to be a highly efficient solution.

Jace vs. Vraska

One of my favourite Magic the Gathering products is by far the duel decks. In each duel deck pack you get two decks designed according to a special theme (e.g. Knights vs. Dragons) or around two planeswalkers (e.g. Koth vs. Venser). The decks are fun and full of flavour and best of all they are designed to be played against one another.

Ever since it was announced I have been looking forward to when the next duel decks would come out and this morning it was finally possible to pre-order Jace vs. Vraska at my local store. Hopefully I will be able to pick up the decks this friday to be able to test them with the kids during the weekend.

Another fun thing about the duel decks is that the deck designer always writes a feature article about the process. Jace vs. Vraska is designed by Sam Stoddard and you can read about his work on the link below.

Playing with Jace & Vraska

This is the code your are looking for

Since it’s obviously impossible for me to remember the best way of getting a random number in Objective-C I’m writing it down here, once and for all. This is a post to my future self.

- “John, this is the code you are looking for!”