Objective-C之Foundation框架的NSMutableDictionary

来源:互联网 发布:c语言技术论坛 编辑:程序博客网 时间:2024/05/27 01:08
//创建一个空的字典
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
Student *stu1 = [Student studentWithName:@"stu1"];
Student *stu2 = [Student studentWithName:@"stu2"];
//添加元素
[dict setObject:sut1 forKey:@"k1"];
//删除所有的元素
[dict removeAllObjects];
//根据一个key删除一个元素
[dict removeObjectForKey:@"k1"];
//删除多个key对应的value
[dict removeObjectsForkey:[NSArray arrayWithObject:@"k1"] ];
原创粉丝点击