OC's "nsmutabledictionary use"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.