Objective-C 2.0学习笔记之NSMutableDictionary
#import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSMutableDictionary *rows=[NSMutableDictionary dictionary];//建立一个空字典 [rows setObject:@"I'm duoduoluo" forKey:@"duoduoluo"];//增加键与值 [rows setObject:@"I'm theboy" forKey:@"theboy"]; NSLog(@"%@",[rows objectForKey:@"duoduoluo"]);//输出 NSMutableDictionary *glossarr=[NSMutableDictionary dictionaryWithObjectsAndKeys: @"I'm duoduoluo", @"duoduoluo", @"I'm theboy", @"theboy", nil ]; for(NSString *key in glossarr)//快速枚举 { NSLog(@"%@",[glossarr objectForKey:key]); } [pool drain]; return 0; } |
输出:
[Session started at 2010-08-21 18:33:12 +0800.]
2010-08-21 18:33:13.036 nsstring[195:903] I’m duoduoluo
2010-08-21 18:33:13.041 nsstring[195:903] I’m duoduoluo
2010-08-21 18:33:13.041 nsstring[195:903] I’m theboy
The Debugger has exited with status 0.
近期评论