簡體   English   中英

比較NSInteger和NSUInteger

[英]Comparing NSInteger and NSUInteger

我需要比較兩個變量,以檢查數組中是否存在索引: indexPath.row是NSInteger [self arrayOfData].count indexPath.row是NSUInteger

問題是它們的類型不同,當indexPath.row = -1時,它會自動轉換為18446744073709551615(無符號長),這是我要避免的。

如何檢查由NSIndexPath的行定義的索引在NSArray是否存在?

碼:

- (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;
    }
}

這是我如何鑄造解決了這個問題unsigned longlong

- (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;
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM