IOS开发-OC学习-Foundation框架练习

OC语言Foundation框架中字典、字符串、数组的应用:

 1 NSString *string = @"China|Usa|France";
 2     
 3     NSArray *array = [string componentsSeparatedByString:@"|"];
 4     NSLog(@"%@",array);
 5     
 6     NSMutableArray *marray = [NSMutableArray arrayWithCapacity:100];
 7     for (int i=0; i<100; i++) {
 8      [marray addObject: [NSString stringWithFormat:@"%dhaha",i]];
 9     }
10 //    删除后二十个元素第一种方法
11     for (int i=0; i<20; i++) {
12         [marray removeLastObject];
13     }
14     
15 //    删除后二十个元素第二种方法
16 //    [marray removeObjectsInRange:NSMakeRange(80, 20)];
17     NSLog(@"%@",marray);
18     
19     
20 //  创建一个字典,key值从0到10,value值从100到110
21 //     先创建两个数组key1和value1
22     NSMutableArray *key1 = [NSMutableArray arrayWithCapacity:11];
23     for (int i=0; i<11; i++) {
24         [key1 addObject: [NSString stringWithFormat:@"%d",i]];
25     }
26     NSMutableArray *value1 = [NSMutableArray arrayWithCapacity:11];
27     for (int i=0; i<11; i++) {
28         [value1 addObject: [NSString stringWithFormat:@"%d",i+100]];
29     }
30 //    创建可变字典
31     NSMutableDictionary *mdic = [NSMutableDictionary dictionaryWithCapacity:11];
32 //    循环给字典添加键值对(键值对由上面代码创建的数组构成)
33     for (int i=0; i<11; i++) {
34         [mdic setValue:[value1 objectAtIndex:i] forKey:[key1 objectAtIndex:i]];
35     }
36     
37     NSLog(@"jjj%@",mdic);
原文地址:https://www.cnblogs.com/jiwangbujiu/p/5313115.html