Check if NSDictionary is empty

后端 未结 8 1375
感情败类
感情败类 2021-02-13 02:22

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:12

    While retrieving the dictionary values from NSUserDefaults that dictionary automatically converted into string that is the reason for getting crashed and for checking dictionary use

    [dictionary count];
    

    EDIT:- use dictionaryForKey: method

    NSDictionary *dict =[[NSDictionary alloc]initWithObjectsAndKeys:@"hi",@"one",nil];
    [[NSUserDefaults standardUserDefaults] setObject:dict forKey:@"dic"];
    NSDictionary *dictn = [[NSUserDefaults standardUserDefaults] dictionaryForKey:@"dic"];
    NSLog(@"%@",[dictn objectForKey:@"one"]);
    

提交回复
热议问题