集合

来源:互联网 发布:网络在线英语培训 编辑:程序博客网 时间:2024/05/17 08:38
   // 无序对象集合 数据不能重复添加        NSSet  *set = [[NSSet alloc]initWithObjects:@"one",@"two",@"three", @"four",@"five",@"one",nil]; // @"one"没有添加进去        NSLog(@"set = %@",set);        //        - (NSUInteger)countForObject:(id)object;        NSMutableSet *mutableSet = [[NSMutableSet alloc]initWithObjects:@"one",@"two",@"three", @"four",@"five",@"one", nil];        //        NSCountedSet *countSet = [NSCountedSet ];                // 长度 count  set.count//        NSUInteger count = [set count];        // 看是否包含某元素       BOOL isContain =  [set containsObject:@"two"];        NSLog(@"是否包含--isCOntain:%d",isContain);//        NSEnumerator *enumrator = [];                        // 添加值        [mutableSet addObject:@"six"];          NSLog(@"mutableSet = %@",mutableSet);        // 删除值        [mutableSet removeObject:@"six"];          NSLog(@"mutableSet = %@",mutableSet);        // 删除所有元素        [mutableSet removeAllObjects];        NSLog(@"mutableSet = %@",mutableSet);     // 无序对象集合 数据不能重复添加        NSSet  *set = [[NSSet alloc]initWithObjects:@"one",@"two",@"three", @"four",@"five",@"one",nil]; // @"one"没有添加进去        NSLog(@"set = %@",set);//        If the same object appears more than once in the list, it is represented only once in the returned set. 如果相同的对象出现在这个列表中超过一次,那么它只会在返回的集合中表示一次                //        - (NSUInteger)countForObject:(id)object;        NSMutableSet *mutableSet = [[NSMutableSet alloc]initWithObjects:@"one",@"two",@"three", @"four",@"five",@"one", nil];                NSCountedSet *countSet = [[NSCountedSet alloc]initWithSet:mutableSet];        NSUInteger count = [countSet countForObject:@"one1"];        NSLog(@"count = %lu",count);                // 长度 count  set.count//        NSUInteger count = [set count];        // 看是否包含某元素       BOOL isContain =  [set containsObject:@"two"];        NSLog(@"是否包含--isContain:%d",isContain);//        NSEnumerator *enumrator = [];                        // 添加值        [mutableSet addObject:@"six"];          NSLog(@"mutableSet = %@",mutableSet);        // 删除值        [mutableSet removeObject:@"six"];          NSLog(@"mutableSet = %@",mutableSet);        // 删除所有元素        [mutableSet removeAllObjects];        NSLog(@"mutableSet = %@",mutableSet);      //    数组转化成集合  NSArray -> NSSet        NSArray *array = @[@"one",@"two",@"three",@"four",@"five"];        NSSet *set = [NSSet setWithArray:array];        NSLog(@"set = %@",set);                //   字典转化成数组   NSDictionary -> NSArray        NSDictionary *dic = @{                              @"name": @"Jack",                              @"age" :  @"18",                              @"height":@"180"                              };                NSArray *keysArray = [dic allKeys];        NSArray *valuesArray = [dic allValues];        NSLog(@"keysArray = %@",keysArray);        NSLog(@"valuesArray = %@",valuesArray);                //  字符串转化成数组 NSString —> NSArray        NSString *string = @"hello world Charles";        NSArray *strsArray = [string componentsSeparatedByString:@" "];        NSLog(@"%@",[strsArray objectAtIndex:0]);        NSLog(@"%@",[strsArray objectAtIndex:1]);        NSLog(@"strsArray = %@",strsArray);            

0 0
原创粉丝点击