NSNumber vs Int

后端 未结 3 1239
太阳男子
太阳男子 2020-12-19 01:22

If integers cannot be written to a dictionary and then to a .plist, but NSNumbers can is it better to use NSNumbers throughout the app, rather than needing to convert every-

3条回答
  •  难免孤独
    2020-12-19 02:08

    It all depends on your need. But, if the API requires you to use int, you should use int. It it asks you to use NSNumber you should use NSNumber.

    For example, if you are using a UISegmentedControl, and you want to select a segment, then,

    [segmentedControl setSelectedSegmentIndex:aIntVar]; // Can not use NSNumber here
    // or
    [segmentedControl setSelectedSegmentIndex:[aNumber intValue]];
    

提交回复
热议问题