有没有办法检查集合是否为空?
NSMutableSet *setEmpty = [[NSMutableSet alloc] init];
// Code to do things...
// Check for empty set?
[setEmpty release];
加里
最佳答案
您可以使用 [setEmpty count] 来查看集合中有多少元素...所以:
if ([setEmpty count] == 0) {
或
if (![setEmpty count]) {
等...
我没有在 http://developer.apple.com/mac/library/documentation/cocoa/Reference/Foundation/Classes/NSSet_Class/Reference/Reference.html 上看到明确的“isEmpty”方法但如果它存在,就去做而不是检查计数。
关于objective-c - 检查空的 NSSet?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1840901/