NSMutableSet 集合成员是无序的。对对象进行枚举所得到对象的顺序不能保证相同。向集合中添加相同对象时只会保留一个副本。和其它集合类一样添加移除对象都会分别收到retain和release消息。
#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    NSMutableSet *fruits = [NSMutableSet setWithCapacity:2];
    [fruits addObject:@"Apple"];
    [fruits addObject:@"Orange"];
    
    //从复添加只记录一条
    [fruits addObject:@"Apple"];
    
    NSLog(@"%@", fruits);

    [pool drain];
    return 0;
}

相关文章:

  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-11
  • 2022-12-23
  • 2021-05-29
  • 2022-12-23
相关资源
相似解决方案