Why NSInteger instead of NSUInteger in “numberOfSectionInTableView:”?

雨燕双飞 提交于 2019-12-06 23:36:54

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/13105917/why-nsinteger-instead-of-nsuinteger-in-numberofsectionintableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!