您的位置:首页 > 其它

集合、可变集合

2015-07-27 08:32 204 查看
<pre name="code" class="objc">int main(int argc, const char * argv[]) {
@autoreleasepool {
//        4 NSArray -> NSSet
NSArray * array = @[@"one",@"two",@"three"];
NSSet * set = [NSSet setWithArray:array];

NSLog(@"%@",set);
//        5 NSDictionary -> NSArray
NSDictionary * dic = @{
@"name":@"Jack",
@"age":@"18",
@"ID":@"1001"
};
NSArray * keysArray = [dic allKeys];

NSArray * valuesArray = [dic allValues];

//6 字符串转换成数组
// 创建字符串
NSString * str = @"I am studying ";
// 传入字符参数分割字符串
NSArray * arrStr = [str componentsSeparatedByString:@"am"];
NSLog(@"arrStr %@",arrStr);
}
return 0;
}


#import <Foundation/Foundation.h>int main(int argc, const char * argv[]) { @autoreleasepool { NSSet * set = [[NSSet alloc] initWithObjects:@"one",@"two",@"three",@"four",@"one", nil]; NSLog(@"%@",set); NSCountedSet// NSSet中不能够存储重复的数据 NSUInteger count = [set
count]; NSLog(@"coutn %lu",count); BOOL isContain = [set containsObject:@"t"]; if (isContain) { NSLog(@"contain"); } else { NSLog(@"not contain"); } } return 0;}

int main(int argc, const char * argv[]) {
@autoreleasepool {
NSMutableSet * set = [[NSMutableSet alloc] initWithObjects:@"one",@"two", nil];
NSLog(@"%@",set);
// 增加值
[set addObject:@"three"];
NSLog(@"%@",set);
// 删除值
[set removeObject:@"two"];
NSLog(@"%@",set);
// 删除所有
[set removeAllObjects];
NSLog(@"%@",set);

}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: