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!”

Default Rotation

When creating an app that should start in landscape mode (mostly games) you should (read must!) support both landscape-left and landscape-right. This is actually a rather simple task, but one thing that has bugged me is that by default the app starts in landscape-left mode (home key to the left). I think it’s way better to start in landscape-right mode, not just because it feels better, most iPad cases (like the Smart Cover and Smart Case) is also designed to be used in landscape-right mode.

But how do you change the default direction? It turned out to be quite simple, you just switch the order of the value-strings for the UISupportedInterfaceOrientations key in the project-info.plist file.

New deck: Allies

Edit: Added sideboard

Our latest Magic the Gathering decks finally arrived today. Hopefully we can find some time this evening to take them out on a test run. On the paper I’m quiet satisfied with my Allies deck, but I still need to figure out a decent sideboard. I’ll get back to that later.

The goal for Allies is to cast at least one ally creature per round, either to pump up other allies or to make other abilities trigger. The Volt Charge will be used to clear the path for the attackers while pumping up the creatures even more. The Door of Destinies is actually a little bit on the expensive side but other than that it fits perfectly in this deck.

The sideboard consists of some protection spells (Cloudshift, Gods Willing and Boros Charm), a few spells to land some extra damage (Mighty Leap and Boros Charm) and some spells to deal with annoying creatures (Pacifism and Coordinated Barrage). The Cloudshift also adds some extra fun since it can be used to double the effect of an Ally entering the battlefield.

Allies
Creatures (25)
4  Hada Freeblade
4  Akoum Battlesinger
2  Highland Berserker
4  Kazandu Blademaster
2  Ondu Cleric
2  Kabira Evangel
2  Makindi Shieldmate
2  Talus Paladin
2  Kazuul Warlord
1  Murasa Pyromancer

Other spells (11)
2  Lightning Bolt
4  Volt Charge
1  Door of Destinies
4  Join the Ranks

Lands (24)
4  Clifftop Retreat
8  Mountain
12  Plains

Sideboard (15)
3  Cloudshift
2  Coordinated Barrage
3  Gods Willing
2  Boros Charm
3  Mighty Leap
2  Pacifism

Small code, Big smile

Sometimes the smallest piece of code can make you happy. Here is a small Objective-C snippet to create a correct CGRect from two CGPoints.

Cards that Needs a Home

There are a few MTG-cards that I really would like to include in a deck but none of my existing decks are the the right one. Kiora and Olivia are two of those cards.

I really like Olivias abilities, first pay to deal 1 damage and to boost Olivia, then pay to gain control of that creature. And since you don’t have to tap her, you can do it as many times per turn as you can afford.

  

I’ve actually already designed a deck including Olivia (see below), but I think it will require some more work until it’s done. For some odd reason these two have almost the same pose, weird but totally unintentional. :-)

Olivias Party
Creatures (22)
2  Shadow Alley Denizen
4  Stromkirk Noble
2  Kalastria Highborn
2  Vampire Interloper
2  Rakish Heir
2  Stromkirk Captain
2  Vampire Nighthawk
2  Heirs of Stromkirk
4  Olivia Voldaren
Other spells (14)
2  Blade of the Bloodchief
2  Lightning Bolt
4  Urge to Feed
4  Volt Charge
2  Whispersilk Cloak

Lands (24)
4  Dragonskull Summit
2  Terramorphic Expanse
9  Mountain
9  Swamp