不可变集合NSSet
![]()
![]()
![]()
![]()
![]()
NSSet和数组一样,是个数据容器
数组是有序的,NSSet是无序的。
数组可以容纳重复的对象,NSSet不能
NSSet的创建
NSSet *set = [NSSet setWithObjects:@“zhangsan”,@“lisi”,nil];//类方法创建
NSSet *set = [[NSSet alloc] initWithObjects:@“zhangsan”,@“lisi”,nil];//alloc创建
将集合转成数组
NSArray *array = [[NSSet alloc] initWithObjects:@“zhangsan”,@“lisi”,nil];
取出元素个数
NSUInteger count = [set count];
从容器中随机取出一个元素
NSString *str = [set anyObject];
判断对象是否存在NSSset中
BOOL isContain = [set containsObject:@“lisi”];
不可变集合的常用方法
可变集合的常用方法
NSNumber
NSValue和NSNull