开发者

Do I need to convert NSUInteger to size_t?

If I have the following code:

NSUInteger i, count = [pages count];
for (i = 0; i < count; i++) {
  Page* page = (Page *)[pages objectAtIndex:i];
  [page setPageN开发者_高级运维umber:[i unsignedIntValue]];
}

PageInfo.pageNumber is a size_t.

Is it still necessary to use [i unsignedIntValue] or do I just assign i directly?


NSUInteger is not an object (it's a typedef for unsigned int on 32-bit or unsigned long on 64-bit; NSNumber, however, is an object), so attempting to call unsignedIntValue on it will probably cause a crash. You can just pass it in directly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜