[Objective-c] 009_foundation framework of Nsdictionary and Nsmutabledictionary

Source: Internet
Author: User
Tags allkeys

In the Cocoa Foundation, nsdictionary and Nsmutabledictionary are used for an ordered collection of objects, Nsdictionary and Nsmutabledictionary and Nsarray and Nsmutablearray are not the same, the former can hold several different types of data, while the latter only holds the same type of data.

1.NSDictionary creation

Nsdictionary *dictionary = [nsdictionary dictionarywithobjectsandkeys:@ "Superdo", @ "Teamname", @ "SuperDo.Horse", @ " Teammember ", nil];

2.NSDictionary traversal

Nsdictionary *dictionary = [nsdictionary dictionarywithobjectsandkeys:@ "Superdo", @ "Teamname", @ "SuperDo.Horse", @ " Teammember ", nil];//gets the number of dictionaries int objectcount = (int) [Dictionary count]; NSLog (@ "Dictionary key number is:%d", objectcount);//Gets all key values in the dictionary nsenumerator * enumeratorkey = [Dictionary keyenumerator];// The fast enumeration iterates through the values of all keys for (NSObject *object in Enumeratorkey) {    NSLog (@ "Key value---":%@ ", object);} Gets all value values in the dictionary nsenumerator * enumeratorvalue = [Dictionary objectenumerator];//Fast enumeration iterates over all value values for (NSObject *object In Enumeratorvalue) {    NSLog (@ "Value---":%@ ", object);}

3.NSDictionary value found by key

Nsdictionary *dictionary = [nsdictionary dictionarywithobjectsandkeys:@ "Superdo", @ "Teamname", @ "SuperDo.Horse", @ " Teammember ", nil]; NSObject *object = [Dictionary objectforkey:@ "Teamname"];if (Object! = nil) {    NSLog (@ "value found through key is:%@", object);}

4.NSMutableDictionary creation

Nsmutabledictionary *dictionary = [Nsmutabledictionary dictionarywithcapacity:10];

5.NSMutableDictionary element operation

Nsmutabledictionary *dictionary = [Nsmutabledictionary dictionarywithcapacity:10];    Dynamically add data to a dictionary [dictionary setobject:@ "Superdo" forkey:@ "Teamname"]; [Dictionary setobject:@ "Superdo.horse" forkey:@ "Teammember"];//through key to find valuensobject *object = [Dictionary objectforkey:@ "Teamname"];//get all Keynsarray *allkeys = [Dictionary allkeys];//get all valuensarray *allvalues = [ Dictionary allvalues];

This site article is for baby bus SD. Team Original, reproduced must be clearly noted: (the author's official website: Baby bus )
Reprinted from "Baby bus Superdo Team" original link: http://www.cnblogs.com/superdo/p/4594337.html

[Objective-c] 009_foundation framework of Nsdictionary and Nsmutabledictionary

Related Article

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.