Hello. I'm Aleksandar Vacić, professional web developer and wine maker in the making.
Learn more about me or see what I can do for you.

My work & services

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.

tags: Programming
Comments: 0

Posted 7 months, 3 weeks agopermanent link

trackback URL: http://aplus.rs/programming/always-use-isequaltostring-for-string-comparisons/trackback/

Voices from the crowd

No comments posted yet. Your chance to be the first.

Post your opinion


? You need to enter your email, but rest assured it will not be published.

? Enter the link and it will be published.
? This blog strives to behave properly, as per XHTML 1.0 Strict spec. You can use the following tags, but please use them wisely:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
? I have enabled comment moderation so if your comment does not shows up after you submit it, don't worry. I will review it and if it's nice and to the point, I'll approve it. This measure is up mostly to fight spam and trolls.

Tags or categories or topics...

Lots of ramblings on this blog...might be easier for you to find your juice through these tags:

Post a job. Find one. authenticjobs.com