字典类的对象是使用方式同数组也类似
主要的方法为
+ dictionaryWithObjectsAndKeys: (id)firstObject, ...;
- (int)count;
- (id)objectForKey:(id)key;
- (NSArray *)allKeys;
- (NSArray *)allValues;
+ (NSMutableDictionary *)dictionary;
- (void)setObject:(id)anObject forKey:(id)key;
- (void)removeObjectForKey:(id)key;
- (void)removeAllObjects;
- (void)addEntriesFromDictionary:(NSDictionary *)otherDictionary;
- NSDictionary *dict=[NSDictionary dictionaryWithObjectsAndKeys:@"name1",@"key1",@"name2",@"key2",nil];
- for (NSString * str_key in [dict allKeys])
- {
- NSLog(@"key is %@",str_key);
- }
- for (NSString * str_val in [dict allValues])
- {
- NSLog(@"value is %@",str_val);
- }
- NSLog(@"value is %@ at %@",[dict objectForKey:@"key1"],@"key1");
- NSMutableDictionary *dict2=[NSMutableDictionary dictionaryWithCapacity:10];
- [dict2 setObject:@"name1" forKey:@"key1"];
- NSLog(@"dict2 value is %@ at %@",[dict2 objectForKey:@"key2"],@"key2");
- [dict2 setObject:@"name2" forKey:@"key2"];
- NSLog(@"dict2 value is %@ at %@",[dict2 objectForKey:@"key2"],@"key2");
