Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSDictionary countForKey

So is there a countForKey or something similar to that for NSDictionary? I do know that there is a count method but is there something like countForKey or do I have to make a NSDictionary category for it?

like image 443
TheAmateurProgrammer Avatar asked Aug 25 '26 21:08

TheAmateurProgrammer


1 Answers

Even though [dictionary count] seems like the easiest approach, you could get the array of keys from the dictionary and then retrieve the array count, so:

NSUInteger keyCount = [dictionary count];

would return the same as:

NSUInteger keyCount = [[dictionary allKeys] count];

EDIT: With the additional information you provided in the comment, if you want to find out how many 'keys' (although your true requirement still isn't that clear):

NSUInteger keyCountForObject = [[dictionary allKeysForObject:object] count];
like image 96
Frank C. Avatar answered Aug 27 '26 13:08

Frank C.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!