Objective-C中字典的使用
2014-03-03 11:46
274 查看
//创建不变字典
NSDictionary *glossary=[NSDictionary
dictionaryWithObjectsAndKeys:[NSNumber
numberWithInt:97],@"nicky",[NSNumber
numberWithInt:95],@"johnson",[NSNumber
numberWithInt:90],@"black",[NSNumber
numberWithInt:100],@"lily",nil];
NSLog(@"%@",glossary);
}
//创建可变字典
NSMutableDictionary *mGlossary=[NSMutableDictionary
dictionary];
[mGlossary setObject:[NSNumber
numberWithInt:97]
forKey:@"nicky"];
[mGlossary setObject:[NSNumber
numberWithInt:95]
forKey:@"johnson"];
[mGlossary setObject:[NSNumber
numberWithInt:90]
forKey:@"black"];
[mGlossary setObject:[NSNumber
numberWithInt:100]
forKey:@"lily"];
NSLog(@"%@",mGlossary);
//删除对象
// [mGlossary removeObjectForKey:@"johnson"];
// NSLog(@"%@",mGlossary);
//利用枚举,遍历对象
NSEnumerator *enumerator;
enumerator=[mGlossary
objectEnumerator];
id obj;
while(obj=[enumerator
nextObject])
{
NSLog(@"I found %@",obj);
}
//遍历关键字
NSEnumerator *enumerator1;
enumerator1=[mGlossary
keyEnumerator];
id obj1;
while(obj1=[enumerator1
nextObject])
{
NSLog(@"I found %@",obj1);
}
NSDictionary *glossary=[NSDictionary
dictionaryWithObjectsAndKeys:[NSNumber
numberWithInt:97],@"nicky",[NSNumber
numberWithInt:95],@"johnson",[NSNumber
numberWithInt:90],@"black",[NSNumber
numberWithInt:100],@"lily",nil];
NSLog(@"%@",glossary);
}
//创建可变字典
NSMutableDictionary *mGlossary=[NSMutableDictionary
dictionary];
[mGlossary setObject:[NSNumber
numberWithInt:97]
forKey:@"nicky"];
[mGlossary setObject:[NSNumber
numberWithInt:95]
forKey:@"johnson"];
[mGlossary setObject:[NSNumber
numberWithInt:90]
forKey:@"black"];
[mGlossary setObject:[NSNumber
numberWithInt:100]
forKey:@"lily"];
NSLog(@"%@",mGlossary);
//删除对象
// [mGlossary removeObjectForKey:@"johnson"];
// NSLog(@"%@",mGlossary);
//利用枚举,遍历对象
NSEnumerator *enumerator;
enumerator=[mGlossary
objectEnumerator];
id obj;
while(obj=[enumerator
nextObject])
{
NSLog(@"I found %@",obj);
}
//遍历关键字
NSEnumerator *enumerator1;
enumerator1=[mGlossary
keyEnumerator];
id obj1;
while(obj1=[enumerator1
nextObject])
{
NSLog(@"I found %@",obj1);
}
相关文章推荐
- Objective-C字典使用详解
- iOS/Objective-C字典对象NSDictionary的使用20130608更新
- Objective-c-字典使用
- iOS/Objective-C开发 字典NSDictionary的深复制(使用category)
- iOS/Objective-C开发 字典NSDictionary的深复制(使用category)
- Objective-C中字典的使用方法总结
- Objective - C 字符串 数组 字典 集合的基本使用
- objective-c 使用NSNumber 将int float long等数据类型加入到数组或字典中
- iOS/Objective-C开发 字典NSDictionary的深复制(使用category)
- 你能熟练使用Dictionary字典和List列表吗?
- Swift3.0 -- 使用字典创建子视图(NSClassFromString创建类的实例)
- 使用SQL视图查出所有的数据库字典
- objective-c(六)文件分离,合成存取方法,方法多参数,局部变量,self使用(未完成)
- Objective-C中使用NSValue、NSNull、NSNumber、NSDecimalNumber、NSData、NSMutableData 小结
- Objective-c 使用c函数
- Objective-C中使用NSValue、NSNull、NSNumber、NSDecimalNumber、NSData、NSMutableData
- 使用code::blocks搭建objective-c的IDE开发环境 支持 @interface
- JS与Objective-C交互(网页与原生交互---使用UIWebviewDelegate)
- Objective-C 省市区 字典 封装
- ORACLE-用户常用数据字典的查询使用方法