How to test NSCFBoolean value?

前端 未结 2 1590
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 00:44

received data from JSON, which is looks like:

{
    myself = 1;
    \"id\" = 123;
}

and I put it into a NSDictionary *messageDic, I also define

相关标签:
2条回答
  • 2021-02-05 01:37

    the result you've got from [messageDic objectForKey:@"myself"], which is a NSNumber, then you need to convert the result to Bool. So try below:

    if ([[messageDic objectForKey:@"myself"]boolValue] == NO)
    
    0 讨论(0)
  • 2021-02-05 01:40

    __NSCFBoolean is a private class that is used in NSNumber class cluster. To extract appropriate value from it you need to use methods from NSNumber class, -boolValue in your case:

    BOOL isMyself = [[messageDic objectForKey:@"myself"] boolValue];
    
    0 讨论(0)
提交回复
热议问题