为了检查数组中是否存在索引,我需要比较两个变量:indexPath.row is NSInteger [self arrayOfData].count is NSUInteger
问题是它们属于不同的类型,当indexPath.row=-1时,它会自动转换为18446744073709551615 (无符号长整型),这是我试图避免的。
如何检查NSArray中是否存在由NSIndexPath的行定义的索引
代码:
- (void) checkIfIndexExists:(NSIndexPath*) indexPath inArray:(NSArray*)arrayOfData {
if (indexPath.row >= [self arrayOfData].count) { // indexPath.row=-1 gets interpretted as 18446744073709551615 (unsigned long)
DDLogDebug(@"Warning: Index doesn't exist {%@}", indexPath);
return;
}
}发布于 2018-07-06 16:48:32
下面是我如何通过将unsigned long转换为long来解决该问题的方法
- (void) checkIfIndexExists:(NSIndexPath*) indexPath inArray:(NSArray*)arrayOfData {
if (indexPath.row >= (long) [self arrayOfData].count) { // indexPath.row=-1 gets interpretted as 18446744073709551615 (unsigned long)
DDLogDebug(@"Warning: Index doesn't exist {%@}", indexPath);
return;
}
}https://stackoverflow.com/questions/51193116
复制相似问题