Check if NSDictionary is empty

后端 未结 8 1371
感情败类
感情败类 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:02

    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.

提交回复
热议问题