Check if NSDictionary is empty

后端 未结 8 943
名媛妹妹
名媛妹妹 2021-02-13 02:40

I want to check if an NSDictionary is empty. I am doing it like this.

  mutDictValues = [[[NSUserDefaults standardUserDefaults] objectForKey:@\"dicV         


        
8条回答
  •  醉酒成梦
    2021-02-13 03:19

    I had a bit different issue but it is related so i would like to share it here.

    I was fetching the webservices & storing data in NSDictionary & again Fetching objectForKey which was Null. So the solution i found is as under

    NSMutableDictionary *result = [NSJSONSerialization JSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
    
        // NSLog(@"%@" , result);
    
        NSMutableDictionary *sup = [result objectForKey:@"keysupplied"];
        NSNull *n=[NSNull null];
        if ( sup ! = n ){
          //Your code if its not null
        }
    

    The reason behind using NSNull was it was returning (NSNull *) when i debugged the application So i finally figured out this way.

提交回复
热议问题