Making an array of integers in iOS

后端 未结 7 1994
悲哀的现实
悲哀的现实 2020-12-07 12:17

If you want to make an array of integers, can you use NSInteger? Do you have to use NSNumber? If so, then why?

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-07 12:24

    If the order of your integers is not required, and if there are only unique values

    you can also use NSIndexSet or NSMutableIndexSet You will be able to easily add and remove integers, or check if your array contains an integer with

    - (void)addIndex:(NSUInteger)index
    - (void)removeIndex:(NSUInteger)index
    - (BOOL)containsIndexes:(NSIndexSet *)indexSet
    

    Check the documentation for more info.

提交回复
热议问题