Check if NSDictionary is empty

后端 未结 8 937
名媛妹妹
名媛妹妹 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:23

    As most of the answers have correctly pointed out that you are passing un-recognized selector objectForKey: to a NSString instance instead of NSDictionary, hence observing exception

    -[__NSCFConstantString objectForKey:]:
    

    Check NSUserDefaults to see whether cities returns a dictionary or something else. You can do this by two ways

    I. NSLog all data in NSUserDefaults

    NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
    

    II. Check the plist file which store the NSUserDefaults from the Application folder. Check this answer for more details.

    Hope that helps.

    0 讨论(0)
  • 2021-02-13 03:26
    if ( [mutDictValues count] == 0 ) {
        //code here
    }
    else {
        //code here
    }
    

    After having your dic retrieved this should do

    0 讨论(0)
提交回复
热议问题