Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 比较NSInteger(或int)与NSInteger(或无符号int)_Objective C_Nsinteger_Nsuinteger - Fatal编程技术网

Objective c 比较NSInteger(或int)与NSInteger(或无符号int)

Objective c 比较NSInteger(或int)与NSInteger(或无符号int),objective-c,nsinteger,nsuinteger,Objective C,Nsinteger,Nsuinteger,我有一个相当大的应用程序(objective-c),我决定打开“符号比较”警告。我现在有将近100个。其中大多数与此类似: if (recentSearches.count > indexPath.row) { //something } Comparison of integers of different signs: 'NSUInteger' (aka 'unsigned int') and 'NSInteger' (aka 'int') 错误与此类似: if (rece

我有一个相当大的应用程序(objective-c),我决定打开“符号比较”警告。我现在有将近100个。其中大多数与此类似:

if (recentSearches.count > indexPath.row) {
    //something
}
Comparison of integers of different signs: 'NSUInteger' (aka 'unsigned int') and 'NSInteger' (aka 'int')
错误与此类似:

if (recentSearches.count > indexPath.row) {
    //something
}
Comparison of integers of different signs: 'NSUInteger' (aka 'unsigned int') and 'NSInteger' (aka 'int')
关于如何解决这些问题,有哪些好的策略或技巧?
真的谢谢,您想继续更改声明,以便在比较时使类型匹配。例如,
count
变量应该是无符号的。这是目前为止最安全的。如果您正在循环使用一个变量,以便将其与其他可能是有符号或无符号的变量进行比较,请更改它! 只有在明确验证了typecast是安全的情况下,才可以这样做。例如,如果有符号整数大于0,则可以将其强制转换为无符号整数。另一个方向是不安全的,除非处理无符号整数可以容纳的值范围,这些值对于有符号整数来说太大