Mobile Development

Strange IB error

Just a tip, if you are using IBOutlets and seperate nib files, if you get a strange error like this:

*** Terminating app due to uncaught exception ‘NSUnknownKeyException’, reason: ‘[<UIViewController 0x44e8b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key viewA.’

Check that the controller class is set correctly for both the Controller in the main file, and the File Owner in the Nib file you are referencing.

This error seems to happen when you link a nib file to a controller in IB, and the class types do not match. Strangley the error only happens when you link an IBOutlet inside that controller though!

This thread describes the problem and solution a little:

http://forums.macrumors.com/archive/index.php/t-576991.html

iPhone UIFont List

Here is a list of fonts available on the iPhone with UIFont.

Font Family: American Typewriter
Font: AmericanTypewriter
Font: AmericanTypewriter-Bold

Font Family: AppleGothic
Font: AppleGothic

Font Family: Arial
Font: ArialMT
Font: Arial-BoldMT
Font: Arial-BoldItalicMT
Font: Arial-ItalicMT

Font Family: Arial Rounded MT Bold
Font: ArialRoundedMTBold

Font Family: Arial Unicode MS
Font: ArialUnicodeMS

Font Family: Courier
Font: Courier
Font: Courier-BoldOblique
Font: Courier-Oblique
Font: Courier-Bold

Font Family: Courier New
Font: CourierNewPS-BoldMT
Font: CourierNewPS-ItalicMT
Font: CourierNewPS-BoldItalicMT
Font: CourierNewPSMT

Font Family: DB LCD Temp
Font: DBLCDTempBlack

Font Family: Georgia
Font: Georgia-Bold
Font: Georgia
Font: Georgia-BoldItalic
Font: Georgia-Italic

Font Family: Helvetica
Font: Helvetica-Oblique
Font: Helvetica-BoldOblique
Font: Helvetica
Font: Helvetica-Bold

Font Family: Helvetica Neue
Font: HelveticaNeue
Font: HelveticaNeue-Bold

Font Family: Hiragino Kaku Gothic ProN W3
Font: HiraKakuProN-W3

Font Family: Hiragino Kaku Gothic ProN W6
Font: HiraKakuProN-W6

Font Family: Marker Felt
Font: MarkerFelt-Thin

Font Family: STHeiti J
Font: STHeitiJ-Medium
Font: STHeitiJ-Light

Font Family: STHeiti K
Font: STHeitiK-Medium
Font: STHeitiK-Light

Font Family: STHeiti SC
Font: STHeitiSC-Medium
Font: STHeitiSC-Light

Font Family: STHeiti TC
Font: STHeitiTC-Light
Font: STHeitiTC-Medium

Font Family: Times New Roman
Font: TimesNewRomanPSMT
Font: TimesNewRomanPS-BoldMT
Font: TimesNewRomanPS-BoldItalicMT
Font: TimesNewRomanPS-ItalicMT

Font Family: Trebuchet MS
Font: TrebuchetMS-Italic
Font: TrebuchetMS
Font: Trebuchet-BoldItalic
Font: TrebuchetMS-Bold

Font Family: Verdana
Font: Verdana-Bold
Font: Verdana-BoldItalic
Font: Verdana
Font: Verdana-Italic

Font Family: Zapfino
Font: Zapfino

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).

What makes a good programmer?

These are some of the things I think make a good programmer:

  1. Don’t tie yourself down to 1 language. The programming language is your tool, just like a hammer is to a builder. You should always use the best tool (language) for the job at hand. Every new language leads to new ways of thinking, and better ways of doing things.
  2. Programming is not just your ‘job’. I’m happy to accept there will be exceptions, however in my opinion if you only program for your job, then you will never be a great programmer. All the greatest programmers I have met, they ‘live’ programming. Note this does not mean you’re supposed to code 24/7, but if you really enjoy programming, then you’re likely to be doing it outside work too.
  3. Understand that there is usually a better way of doing things, but sometimes you have to find the balance. Its not always best to spend 6 months writing an awesome bit of code, sometimes you have to be able to analyze whats really needed. Your time might be better spent writing a rough prototype of the code, so other members of the team can get started quicker. You can always go back to re-factor it later.
  4. Learn to analyze and predict problems in advance. When your making changes, think of the repercussions and how it effects other parts of the code.
  5. Test your code properly. A QA team is no excuse for not testing code properly yourself. Ideally you should also have some way of automating tests too.
  6. Split up problems into management chunks. If you have a long list of things that need changing, try to split them up into completely separate tasks. Its very easy to start making too many changes in one go, and then it gets confusing when things go wrong (at what point did I break that bit of code, was it fix A, B or C??). The best way, is to make small changes that do not break the code for long periods of time. This way changes can regularly be committed to revision control, which makes life a lot easier when you need to track your changes to find the source of a bug, or roll back to a earlier version.
  7. Don’t be a rebel, respect the existing code style. If you are working in a team, you should all be working to the same code style. Being a rebel and going against the grain is not smart or clever. You might think that your code style is superior, but no one cares! Code with 1 consistent style is much easier to read, than one with 10 different code styles, from 10 different programmers who all think they know best.
  8. Work well with others and respect other people’s views and abilities. Programming is as much about being able to work on your own, as it is being able to work well in a team.

Stopping comment spam

Over the past few days I’ve been getting over 100 per day spam comments from bots. They don’t show up until moderated, but I get an email for every single one, and I have to manually mark them for deletion.

So I installed a Captcha plugin for wordpress, which will hopefully stop those bots from posting for a while :)

If you add a comment, you should notice a image verification box, which you’ll need to show for your comment to be accepted.

Nokia invalid JAR

Quite a fun problem.

Installing an application from the JAD says invalid JAR on some Nokias, but installing direct from the JAR works fine.

The problem as it turns out, is that there is a bug on some Nokias where if the version ends in a 0 (i.e 1.1.0), it says its invalid.

Very stupid, and very annoying bug. Thanks Nokia

Ruby Kernel.fork on Windows

Kernel.fork is used to start a subprocess, which is sometimes needed over just a Ruby thread (which is still part of the current process). Unfortunately it doesn’t work on Windows because Windows doesn’t support the fork(2) command.

However, it does work under cygwin! Which is really useful :)

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.

J2me threading issues on Nokia S60

Had a strange thing happen with the Nearme app I’m working on. When installed onto the phone memory, the app is blistering fast on my N95. But when installed onto the mass memory (memory card), it runs incredibly slow during network activity.

It just sounds like bad threading code, but the GUI and the network are in separate threads and considering it runs very well on phone memory, and on other handsets, it leads me to believe its an issue with j2me apps on the memory card.

I will post an update once i’ve gotten to the bottom of it. I’d be interested to hear if anyone else has seen this.