您的位置:首页 > 其它

NSMutableDictionary

2015-06-04 16:15 246 查看
//NSMutableDictionary

#import “Student.h”

#pragma mark use of NSMutableDictionary

void dictUse(){

Student *stu1=[Student studentWithName:@”stu1”];

Student *stu2=[Student studentWithName:@”stu2”];

//create a mutable void dict

NSMutableDictionary  *dict=[NSMutableDictionary dictionary];

//add elements

//add student class

//Way1:







//If not check that ,in current project only quote

//if just quote ,never check move to trash,it will delete original file.





//Way2

//Select the files and move to your current project

 



//Personal opinion better copy









[dict setObject:stu1  forKey:@“k1”];//counter=2

NSLog(@”stu1:zi%”,[stu1 retainCount]);

[dict setObject:stu2 forKey:@”k2”];

}





//check which files are added to your project





//Tips

//If you import some files from outside,check whether they are compiled.

//When the dict is destroied , all the keys and values  inside will be reduce counter

//Add content of other dictionary into current dictionary

NSDictory *other=[NSDictionary dictionaryWithObject:@”v2” forKey:@”k2”];

[dict addEntriesFromDictionary:other];

//delete element

[dict removeAllObjects];// Remove all keys and values

[dict removeObjectForKey:@”k1”];

// remove object according to key stu1

//Remove objects base on multi-keys

[dict removeObjectsForKeys:[NSArray arrayWithObject:@”k1”]];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: