MAIN.M file
#import <Foundation/Foundation.h>
#import "Student.h"
#pragma the use of the mark variable dictionary
void Dictuse () {
Create an empty Dictionary
Nsmutabledictionary *dict = [Nsmutabledictionarydictionary];
Student *STU1 = [studentstudentwithname:@ "STU1"];
Student *stu2= [studentstudentwithname:@ "STU2"];
adding elements
The STU1 counter will be +1
[Dictsetobject:stu1 forkey:@ "K1"];
NSLog (@ "Stu1:%zi", [Stu1retaincount]);
Add other dictionaries to the current dictionary Dict
Nsdictionary *other = [nsdictionarydictionarywithobject:@ "v2" forkey:@ "K2"];
[Dict Addentriesfromdictionary:other];
Remove all key-value pairs
[Dict removeallobjects];
Delete K1 corresponding element stu1,stu1 will do a release operation once
[Dict removeobjectforkey:@ "K1"];
NSLog (@ "Stu1:%zi", [Stu1retaincount]);
Delete multiple keys corresponding to value
[Dict removeobjectsforkeys:[nsarray arraywithobject:@ "K1"];
When the dictionary is destroyed, all internal key and value counters will be-1, which means STU1 will release once
}
int main (int argc,const char * argv[])
{
@autoreleasepool {
Dictuse ();
}
return 0;
}
OC's "nsmutabledictionary use"