Mobile Development

Gotcha with Obj-C properties

Properties in Objective-C can be quite useful sometimes, but you have to be careful because they don’t always work how you think they should. Here is a common gotcha among people new to Obj-C and properties.

Consider we have a class called Sprite, which has a property called position.

@interface Sprite : NSObject {
  CGPoint position;
}

@property (readwrite) CGPoint position;

@end

CGPoint is a struct with 2 int variables, x and y.

Lets create one:

Sprite mySprite* = [[Sprite alloc] init];

Now consider the situation of getting and setting the position.

Getting
When you call this:

CGPoint pos = mySprite.position;

It is actually the same as:

CGPoint pos = [mySprite position];

Here its clear that pos is a copy of the position (its not a reference
to the instance variable).

Setting
When you can call:

mySprite.position = pos;

It is actually the same as:

[mySprite setPosition:pos];

OK this is probably fairly clear so far!

The Gotcha
Now this is where the issue happens.

When you call this:

mySprite.position.y = 99;

It is actually the same as this:

[mySprite position].y = 99;

In this instance, the position variable of mySprite is not changed at all.

So when using properties, try to be aware of what Objective-C is actually doing behind the scenes :)

Deactivate iTunes account on iPhone

Was having trouble figuring out how to deactivate the itunes account on the iPhone.

I finally figured it out though:

1. Plug in your iPhone into your computer.
2. Open up iTunes.
3. Sign out of iTunes account on your computer (on Mac, this is under the Store menu).

Automated Blackberry sign tool (Mac, Linux & Windows)

There is a way to get Blackberry to be built and signed, on Mac, Linux & Windows. Heres how:

BB Ant tools

Need I say more? Well for the most part no, these tools work exactly like described. All you need is the JDE bin and lib folders, and the ant tasks for bb-ant-tools.

However if you need to get the signing tool to work, there is a little bit of info you need to know:

The signing tool looks for 2 files: sigtool.csk and sigtool.db
These must be in the bin folder for the JDE, alongside the SignatureTool.jar.
If your on windows, this works fine. If your on mac or linux, this doesn’t. Why? Because the SignatureTool is stupid.

It looks for the files like this: “..\bin\sigtool.csk”. So on anything that doesn’t use \ for dir seperators, this doesn’t work. You can trick it though, by making a softlink:

% ln -s bin/sigtool.csk bin\\sigtool.csk
% ln -s bin/sigtool.db bin\\sigtool.db

The signature tool now finds the files, yay!

Most people think the signature tools are restricted to your machine. However they are not. The csk and db file can be put on any machine, and the signatureTool will work. Be careful you don’t distribute your registration files though, because thats what RIM use to trace a malicious application.

For our development, I have put the JDE’s bin and lib folder into our subversion repository. So all developers can sign and build without needing to install the JDE, and it doesn’t matter what OS they are running either :)

Hope this is useful to someone, because theres not much info out there on BlackBerry development on other OS.

N95 sync on Mac

I asked myself a question: “Hmm, I wonder if its possible to sync my N95 with my mac”. My answer: “Doubt it”

Funny that, I am now not only able to sync my N95 with my Mac, I also don’t need todo anything because it does it all automatically when I move my N95 within bluetooth range of my Mac. I love my Mac :)

For those wondering how I did it, I followed this useful guide that pretty much walked me through it. To summarise what you need from that post:

  1. iSync

    This was already on my Macbook with Leopard.

  2. Nokia N95 plugin for iSync

    This was probably the only step that caused me problems. The latest version of iSync is 3.0, and Nokia’s iSync plugins are only for 2.4. So in the end, I had to purchase a plugin from here. It was only 8 pounds though, so for me it was well worth it.

  3. Home Zone

    This is what detects when your device gets in Bluetooth range and starts a script. You can get it from here.

  4. Automator app for the sync

    You can get this from here. You just need to unzip it, and put it in your Applications folder (or somewhere you can find it).

I recommend following through the guide though, its pretty straight forward :)