How to determine the true data type of an NSNumber?

前端 未结 4 1494
悲哀的现实
悲哀的现实 2020-12-02 00:22

Consider this code:

NSNumber* interchangeId = dict[@\"interchangeMarkerLogId\"];
long long llValue = [interchangeId longLongValue];
double dValue = [intercha         


        
4条回答
  •  醉话见心
    2020-12-02 01:19

    Simple answer: You can't.

    In order to do what you're asking, you'll need to keep track of the exact type on your own. NSNumber is more of a "dumb" wrapper in that it helps you use standard numbers in a more objective way (as Obj-C objects). Using solely NSNumber, -objCType is your only way. If you want another way, you'd have to do it on your own.

    Here are some other discussions that may be of help:

    get type of NSNumber

    What's the largest value an NSNumber can store?

    Why is longLongValue returning the incorrect value

    NSJSONSerialization unboxes NSNumber?

提交回复
热议问题