<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;
}