Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why NSInteger instead of NSUInteger in "numberOfSectionInTableView:"?

The UITableView data source method numberOfSectionsInTableView: has a return type of NSInteger. However, a UITableView cannot have a negative amount of rows; it has 0 or greater rows, so why is the return type of NSInteger? Doesn't that allow for crashes relating to a negative integer being returned?

like image 723
pasawaya Avatar asked Oct 28 '12 02:10

pasawaya


1 Answers

You can't do the check (if var < 0) return; with an unsigned integer. That is the standard reason for preferring one. Really the only reason to use an unsigned integer is if you need the extra room for larger digits, and you can guarantee the input will never try to be less than zero.

like image 190
borrrden Avatar answered Sep 18 '22 17:09

borrrden