Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a NSMutableDictionary is empty?

Tags:

objective-c

How can I tell if an NSMutableDictionary is empty in Objective-C?

like image 629
John Avatar asked Jan 20 '11 23:01

John


People also ask

How do you check if an NSDictionary has a key?

If you wish to check if the NSDictionary contains any key (non-specific) you should use [dictionary allKeys]. count == 0 If the count is 0 there are no keys in the NSDictionary .

How to check Dict is empty in Swift?

To check if a Dictionary is empty in Swift, check isEmpty property of this Dictionary instance. isEmpty property returns a boolean value of true if the dictionary is empty, or false if the dictionary is not empty.

How do I check if a Dictionary is null in Objective C?

Sending a message to nil / NULL is always valid in Objective-C. So it depends if you want to check if a dictionary is nil , or if it doesn't have values (as a valid dictionary instance may be empty). In the first case, compare with nil . Otherwise, checks if count is 0, and ensure you're instance is still valid.

What is NSMutableDictionary?

An object representing a dynamic collection of key-value pairs, for use instead of a Dictionary variable in cases that require reference semantics.


1 Answers

Very simple, use the -count method inherited from NSDictionary:

NSMutableDictionary *dict = ...  BOOL isEmpty = ([dict count] == 0); 
like image 180
Jacob Relkin Avatar answered Sep 20 '22 16:09

Jacob Relkin