I'm getting the following warning Comparison of unsigned expression < 0 is always false.
I'm not sure how to fix it ?
if(topWindowIndex < 0)
It's defined as...
NSUInteger topWindowIndex = [allWindows count] - 1;
I'm getting the following warning Comparison of unsigned expression < 0 is always false.
I'm not sure how to fix it ?
if(topWindowIndex < 0)
It's defined as...
NSUInteger topWindowIndex = [allWindows count] - 1;
If [allWindows count] - 1 can never be negative, the test (and the code it controls) is unnecessary. If it can be negative, you should declare topWindowIndex as a signed type (int or NSInteger).
A better solution, IMO, is to store the count directly and use that instead:
NSUInteger numWindows = [allWindows count];
...
if (numWindows < 1) ...
这很危险
NSUInteger topWindowIndex = [allWindows count] - 1;
如果[allWindows count]是 0,你会得到一个非常大的数字(废话)作为 topWindowIndex。
上述答案的基本答案:
使用NSInteger代替NSUInteger(无符号)。