The Blog

Always use isEqualToString for string comparisons

While working on my iPhone app Quickie, I encountered one of many examples why you must always check your code on the actual device.

Quickie uses Core Data for storage and in one particular place I was comparing the NSString variable to a NSString–typed property of my CoreData class, QuickieList. Like this:

OBJC:
  1. if (QuickieList.listName != theListName)

listName is defined as NSString and theListName is obviously that as well. In this particular instance, both of those had the value of “test”.
In the iPhone Simulator (running on 10.6.2) this comparison returned false, but on the iPhone running 3.1.2 it returned true. When changed into:

OBJC:
  1. if (![QuickieList.listName isEqualToString:theListName])

result was the same.

Never – I repeat — never assume that simulator testing will be fine, even for seemingly small things. It can bite you when you least expect it.

Banca

Banca

Beautiful and functional currency converter, supports just about any currency in the world.

Go Couch to 5k

Go Couch to 5k

The most popular starter running program in beautiful feature-rich app (GPS tracking, charts, detailed history etc)

Quickie to do

Quickie to do

The fastest short-term task-list / check-list app on the App Store. Really.

Guerrilla Cardio

Guerrilla Cardio

The most challenging high-impulse interval training in the world.

Run Mate

Run Mate

A versatile running coach app, with unlimited number of running programs. Perfect for casual runners.

One Comment

Feel free to chime in, looking forward to it. Leave a Comment

  1. Steve White says:

    Thanks for the tips so far.

    I’m in the starting stages of my app company. I have more of a design/photography background and am working with a programmer.

    The first thing I did was link my phone and run tests. The first thing I noticed was a crash when scrolling through a thumbnail list. I tested on the simulator and there were no hiccups.

    Once linked, testing on the phone is just as quick as loading it onto the simulator, so there’s no excuse not to.

    Steve White
    dadico apps

Comments are now closed for this article.