views:

19

answers:

1

If I have the following code:

NSUInteger i, count = [pages count];
for (i = 0; i < count; i++) {
  Page* page = (Page *)[pages objectAtIndex:i];
  [page setPageNumber:[i unsignedIntValue]];
}

PageInfo.pageNumber is a size_t.

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

+2  A: 

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.

Wevah
Hmm, yeah, I now see the warning when I try to call unsignedIntValue. Weird for Xcode's autocomplete to suggest that it was a valid call. Oh well. Thanks!
Altealice