get type of NSNumber

后端 未结 12 600
鱼传尺愫
鱼传尺愫 2020-11-29 02:33

I want to get the type of NSNumber instance.

I found out on http://www.cocoadev.com/index.pl?NSNumber this:

 NSNumber *myNum = [[NSNumber alloc] initWithB         


        
12条回答
  •  悲&欢浪女
    2020-11-29 03:04

    If all you want is to differentiate between booleans and anything else, you can make use of the fact that boolean NSNumbers always return a shared instance:

    NSNumber *num = ...;
    if (num == (void*)kCFBooleanFalse || num == (void*)kCFBooleanTrue) {
       // num is boolean
    } else {
       // num is not boolean
    }
    

提交回复
热议问题