Cocoa 入门8
字典– NSDictionary
是使用键值配对(条目)来储存和获取对象的,就像1 对应 A ,2 对应 B等等。
例子:
NSArray *keys = [@"one two three four" componentsSeparatedByString: @" "];
NSArray *values = [@"diy how-to hobby geek" componentsSeperatedByString: @" "];
//建立两个NSArray 数组,并按照字符串之间的空格进行分割储存
NSDictionary *dict = [[NSDictionary alloc] initWithObjects: values forKeys: keys];
printf (“%s\n”, [[dict description] UTF8String]);
//用keys 和 values创建一个新的字典,并输出
结果如下:
one = diy;
four = geek;
three = hobby;
two = how-to;
——————————————————————
可变字典 — NSMutableDictionary 同 NSMutableString、NSMutableArray 类似:
- setObject: [...]
Recent Comments