TA的每日心情 | 汗 2024-10-15 10:05 |
---|
签到天数: 372 天 [LV.9]以坛为家II
|
本帖最后由 Sian 于 2013-12-22 21:37 编辑
- #import <Foundation/Foundation.h>
- int main(int argc, const char * argv[])
- {
- @autoreleasepool{
- NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"One",@"1",@"Two",@"2",@"Three",@"3",nil];
-
- NSLog(@"%@",dict);
-
- NSEumerator * eumerator = [dict objectEumerator];
- id obj;
- while(obj = [eumerator nextObject]){
- NSLog(@"%@",obj);
- }//枚举器法
-
- for(id obj in dict){
- NSLog(@"%@",obj);
- NSLog(@"%@",[dict objectForKey:obj]);
- }
- [dict release];
- }
- }
复制代码 可变字典- #import <Foundation/Foundation.h>
- int main(int argc, const char * argv[])
- {
- @autoreleasepool{
- NSMutableDictionay * dict = [[NSMutableDictionay alloc] init];
-
- [dict setObject:@"One" forKey:@"1"];//增加一个键值对
- [dict setObject"@"Two" forKey:@"2"];
-
- NSLog(@"%@",dict);
-
- [dict removeObjectForKey:@"1"];//删除一个键值对
-
- NSLog(@"%@",dict);
-
- [dict release];
- }
- }
复制代码
|
|