Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking for empty NSSet?

Tags:

objective-c

Is there a way to check if a set is empty?

NSMutableSet *setEmpty = [[NSMutableSet alloc] init];

// Code to do things...

// Check for empty set?

[setEmpty release];

gary

like image 576
fuzzygoat Avatar asked Dec 03 '09 16:12

fuzzygoat


1 Answers

You can use [setEmpty count] to see how many elements are in the set... so:

if ([setEmpty count] == 0) {

or

if (![setEmpty count]) {

etc...

I didn't see an explicit 'isEmpty' method on http://developer.apple.com/mac/library/documentation/cocoa/Reference/Foundation/Classes/NSSet_Class/Reference/Reference.html but if it exists, go for that instead of checking the count.

like image 112
Malaxeur Avatar answered Oct 03 '22 12:10

Malaxeur