-4

I am having some very frustrating trouble on what I'm sure is a very simple problem, but I cannot seem to fix it. I have an NSArray called final that outputs as follows:

final = (
".DS_Store",
"hey.txt"
)

I want the following for loop to return false for the first pass and true for the second. As far as I can tell I have it made correctly but the output is true for both passes.

for (int i = 0; i < [final count]; i++) {
   if (final[i] != @".DS_Store") {
    NSLog(@"true");
   }
   else {
    NSLog(@"false");
   }

Outputs:

2013-02-20 17:20:39.042 myAppName [40636:403] true
2013-02-20 17:20:39.042 myAppName [40636:403] true

I cannot figure out why the first one does not return false. Any Ideas?

Sebastian
  • 7,670
  • 5
  • 38
  • 50
Andrew Doig
  • 25
  • 2
  • 9

1 Answers1

2

You are comparing pointers. Use [final[i] isEqualToString:@".DS_Store"] to compare strings.

Sebastian
  • 7,670
  • 5
  • 38
  • 50
  • Yes! I knew it was a simple answer. Is there an unequal one? Like isNotEqualtoString? – Andrew Doig Feb 20 '13 at 22:30
  • No there isn't. But that's just basic C/Objective-C. Actually it's basic programming in any language, so I'll let you figure that one out for yourself. – Sebastian Feb 20 '13 at 22:32