//1.NSNumber-->一个基本数据类型的类簇(将基本类型变为对象)
NSNumber * intnum = [[NSNumber alloc] initWithInt:1];
NSNumber * floatnum = [[NSNumber alloc] initWithFloat:0.2f];
NSNumber * doublenum = [[NSNumber alloc] initWithDouble:3.2];
NSNumber * charnum = [[NSNumber alloc] initWithChar:1];
//比较对象的大小
NSNumber * intnum2 = [[NSNumber alloc] initWithInt:6];
//比较两个数字对象是否相等,可以互相比较
BOOL result = [intnum isEqualToNumber:intnum2];
BOOL result2 = [intnum isEqualToNumber:floatnum];
BOOL result3 = [doublenum isEqualToNumber:floatnum];
if ([intnum2 compare:intnum] == NSOrderedAscending) {
NSLog(@"<");
}else if([intnum2 compare:intnum]==NSOrderedSame){
NSLog(@"==");
}else if([intnum2 compare:intnum]==NSOrderedDescending){
NSLog(@">");
}
NSLog(@"%d",[intnum intValue]);
NSLog(@"%f",[floatnum floatValue]);
NSLog(@"%f",[doublenum doubleValue]);
NSLog(@"%c",[charnum charValue]);
NSNumber * intnum = [[NSNumber alloc] initWithInt:1];
NSNumber * floatnum = [[NSNumber alloc] initWithFloat:0.2f];
NSNumber * doublenum = [[NSNumber alloc] initWithDouble:3.2];
NSNumber * charnum = [[NSNumber alloc] initWithChar:1];
//比较对象的大小
NSNumber * intnum2 = [[NSNumber alloc] initWithInt:6];
//比较两个数字对象是否相等,可以互相比较
BOOL result = [intnum isEqualToNumber:intnum2];
BOOL result2 = [intnum isEqualToNumber:floatnum];
BOOL result3 = [doublenum isEqualToNumber:floatnum];
if ([intnum2 compare:intnum] == NSOrderedAscending) {
NSLog(@"<");
}else if([intnum2 compare:intnum]==NSOrderedSame){
NSLog(@"==");
}else if([intnum2 compare:intnum]==NSOrderedDescending){
NSLog(@">");
}
NSLog(@"%d",[intnum intValue]);
NSLog(@"%f",[floatnum floatValue]);
NSLog(@"%f",[doublenum doubleValue]);
NSLog(@"%c",[charnum charValue]);
//2.NSSet使用,有序集合 NSSet 集合 和 NSMutabelSet和 NSIndexSet (索引集合)
//和NSArray数组相同但是却是无序的,
NSSet *set = [[NSSet alloc] initWithObjects:@"hello",@"china",@"names", nil];
NSLog(@"%@",set);
NSLog(@"%lu",[set count]);
//判断是否包含某个元素
bool rest =[set containsObject:@"hello"];
NSLog(@"%d",rest);
NSSet *set2 = [[NSSet alloc] initWithObjects:@"hello",@"china",@"names",@"jim", nil];
//判断两个集合是否相等
BOOL res = [set isEqual:set2];
NSLog(@"%d",res);
//判断第一个集合是否是第二个集合的子集合
BOOL res3 = [set isSubsetOfSet:set2];
//迭代数据
NSEnumerator * enu = [set objectEnumerator];
NSString *str;
while (str = [enu nextObject]) {
NSLog(@"%@",str);
}
NSArray *arry = [[NSArray alloc] initWithObjects:@"hello",@"china",@"names", nil];
//使用数组初始化集合
NSSet *news = [[NSSet alloc] initWithArray:arry];
//NSMUtableSet使用动态创建
NSMutableSet * muset = [[NSMutableSet alloc] init];
//动态添加set集合元素
[muset addObject:@"one"];
[muset addObject:@"two"];
[muset addObject:@"three"];
//当集合中有重复元素时,实际上只保存一个
[muset addObject:@"three"];
NSLog(@"%@",muset);
//将一个set集合放入新的集合
NSSet * s = [[NSSet alloc] initWithObjects:@"thi",@"mi", nil];
[muset unionSet: s];
NSLog(@"%@",muset);
//将添加的集合删除
[muset minusSet:s];
NSLog(@"%@",muset);
//NSIndexSet
索引集合
// 存放的是数字集合
NSIndexSet *indexset = [[ NSIndexSet alloc ] initWithIndexesInRange : NSMakeRange ( 1 , 2 )];
// 集合中的数字是 2 , 3 , 4
NSArray *arry = [[ NSArray alloc ] initWithObjects : @"hello" , @"china" , @"names" , @"hi" , @"hih" , nil ];
NSArray * newa = [arry objectsAtIndexes :indexset];
NSLog ( @"%@" ,newa);
//和NSArray数组相同但是却是无序的,
NSSet *set = [[NSSet alloc] initWithObjects:@"hello",@"china",@"names", nil];
NSLog(@"%@",set);
NSLog(@"%lu",[set count]);
//判断是否包含某个元素
bool rest =[set containsObject:@"hello"];
NSLog(@"%d",rest);
NSSet *set2 = [[NSSet alloc] initWithObjects:@"hello",@"china",@"names",@"jim", nil];
//判断两个集合是否相等
BOOL res = [set isEqual:set2];
NSLog(@"%d",res);
//判断第一个集合是否是第二个集合的子集合
BOOL res3 = [set isSubsetOfSet:set2];
//迭代数据
NSEnumerator * enu = [set objectEnumerator];
NSString *str;
while (str = [enu nextObject]) {
NSLog(@"%@",str);
}
NSArray *arry = [[NSArray alloc] initWithObjects:@"hello",@"china",@"names", nil];
//使用数组初始化集合
NSSet *news = [[NSSet alloc] initWithArray:arry];
//NSMUtableSet使用动态创建
NSMutableSet * muset = [[NSMutableSet alloc] init];
//动态添加set集合元素
[muset addObject:@"one"];
[muset addObject:@"two"];
[muset addObject:@"three"];
//当集合中有重复元素时,实际上只保存一个
[muset addObject:@"three"];
NSLog(@"%@",muset);
//将一个set集合放入新的集合
NSSet * s = [[NSSet alloc] initWithObjects:@"thi",@"mi", nil];
[muset unionSet: s];
NSLog(@"%@",muset);
//将添加的集合删除
[muset minusSet:s];
NSLog(@"%@",muset);
// 存放的是数字集合
NSIndexSet *indexset = [[ NSIndexSet alloc ] initWithIndexesInRange : NSMakeRange ( 1 , 2 )];
// 集合中的数字是 2 , 3 , 4
NSArray *arry = [[ NSArray alloc ] initWithObjects : @"hello" , @"china" , @"names" , @"hi" , @"hih" , nil ];
NSArray * newa = [arry objectsAtIndexes :indexset];
NSLog ( @"%@" ,newa);