I am developing an app in iPhone
我正在开发iPhone的应用程序
I am using an NSRange object in my code.
我在我的代码中使用NSRange对象。
if (range.length == 0) { do something }
if(range.length == 0){做某事}
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.
当我在控制台上打印range.length的值时,它写入0.这意味着我的if条件保持有效。但它永远不会进入循环内部去做某事。
Any clue what I might be doing wrong?
我有什么可能做错的任何线索?
Thanks AJ
1 个解决方案
#1
The NSRange is a struct defined like this:
NSRange是一个像这样定义的结构:
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.
如果(myRange.length == 0)不为真,则范围的长度不为0.比较正确,在别处搜索您的问题。使用调试器可以准确了解发生了什么以及何时发生。
#1
The NSRange is a struct defined like this:
NSRange是一个像这样定义的结构:
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.
如果(myRange.length == 0)不为真,则范围的长度不为0.比较正确,在别处搜索您的问题。使用调试器可以准确了解发生了什么以及何时发生。