- iOS从零基础到精通就业 Objective-C
- CSDN观看地址:http://edu.csdn.net/course/detail/3347
- 集合
-
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { //不可变集合 //跟字典一样没有顺序 //去除重复的元素 //NSSet *set1 = [[NSSet alloc] initWithObjects:<#(nonnull id), ...#>, nil]; NSSet *set1 = [NSSet setWithObjects:@"aaa",@"bbb",@"ccc",@"ddd",@"aaa",@"ccc", nil]; NSLog(@"%@",set1); //获取集合中的元素 NSString *str = [set1 anyObject]; NSLog(@"%@",str); //可变集合 NSMutableSet *mSet = [NSMutableSet set]; [mSet addObject:@"1111"]; [mSet addObject:@"2222"]; [mSet addObject:@"3333"]; [mSet addObject:@"4444"]; [mSet addObject:@"1111"]; NSLog(@"%ld",[mSet count]); [mSet removeObject:@"3333"]; NSLog(@"%ld",[mSet count]); //计数集合 NSCountedSet *cSet = [NSCountedSet set]; [cSet addObject:@"1111"]; [cSet addObject:@"2222"]; [cSet addObject:@"3333"]; [cSet addObject:@"4444"]; [cSet addObject:@"1111"]; [cSet addObject:@"1111"]; [cSet addObject:@"2222"]; [cSet addObject:@"1111"]; [cSet addObject:@"1111"]; NSLog(@"%ld",[cSet countForObject:@"1111"]); int a = 10; int b = 20; NSString *astr = [NSString stringWithFormat:@"%d",a]; NSString *bstr = [NSString stringWithFormat:@"%d",b]; NSArray *array = [NSArray arrayWithObjects:astr,bstr, nil]; NSString *result = [array objectAtIndex:0]; int a1 = [result intValue]; NSLog(@"%d",a1); float f1 = 9.99; NSNumber *n1 = [NSNumber numberWithFloat:f1]; NSArray *array1 = @[n1]; NSNumber *resultNumer = array1[0]; float resultFloat = [resultNumer floatValue]; return 0; }