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.
精彩评论