Check if NSDictionary is empty

后端 未结 8 946
名媛妹妹
名媛妹妹 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.

提交回复
热议问题