开发者

Do I need to convert NSUInteger to size_t?

开发者 https://www.devze.com 2023-01-16 18:56 出处:网络
If I have the following code: NSUInteger i, count = [pages count]; for (i = 0; i < count; i++) { Page* page = (Page *)[pages objectAtIndex:i];

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

精彩评论

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