Tech and a few other things RSS 2.0
# Friday, January 01, 2010


The Problem:
Not being able to do a simple compare in an "if statement" between two alpha or numerical statements while programing in objective C.

The Solution:
NSOrderedSame

Example Of Use:
This compares the value of "key" to the value of "support." If they are equal then you get a return value of true.
if ([key compare:Support] == NSOrderedSame)
Explanation:
For some reason Objective-C decided to make it a little bit harder to compare values. Instead of just using the traditional way "[key compare:Support]" return a true value for the if statement OR "([key compare:Support] == 0) OR "([key compare:Support] == true)" they decided to make it a little bit more complex. As demonstrated above. I'm sure the writers of Objective-C have a good reason for this, but one more level of abstraction could make Objective-C that much friendlier to it's programmers and isn't that what it's all about in the end...getting more people to develop in your language.

Some of other comparisons you might want to use are:
NSOrderedAscending -- The left operand is smaller than the right operand.
This is equivalent to using "<" in most languages.

NSOrderedDescending -- The left operand is greater than the right operand.
This is equivalent to using ">" in most languages.
Friday, January 01, 2010 7:51:02 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Mac | Mac OS X | Objective C
Comments are closed.
Navigation
About the author/Disclaimer
        

My name is Ben Coffman. I like to build things: programs, programming teams, programming departments and maybe one day a company with lots of programmers. When I turn the internet off I focus on my family, random hobbies, and sharing moments in life.

Blogs I follow:

1. 2andahalfd.com

2. Jeff Lamarche

3. Scott Hanselman

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Ben Coffman

Archive
<February 2012>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910
All Content © 2012,

Sign In