Question

I am developing an app in iPhone

I am using an NSRange object in my code.

if (range.length == 0) { do something }

When I print the the value of range.length on the console it writes 0. Which means my if condition holds valid. But it never enter inside the loop to do something.

Any clue what I might be doing wrong?

Thanks AJ

Was it helpful?

Solution

The NSRange is a struct defined like this:

typedef struct _NSRange {
    NSUInteger location;
    NSUInteger length;
} NSRange;

If (myRange.length == 0) is not true, the length of your range is not 0. The comparison is right, search elsewhere for your problem. Use the debugger to see exactly what's going on and when.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top