Call notes between an array and a dictionary

Source: Internet
Author: User

June 16, 2015

Personal Summary:

Note: Dictionaries and arrays are ID types, and if there are values, note the type conversions;

Dictionaries and arrays are defined and assigned in many similar places and can be remembered together;

Array  

Definition Nsarray *array = [[Nsarray alloc] init];

Definition Nsarray *array = [Nsarray array];

Define and assign a value nsarray *array = [Nsarray arraywithobject:@ ""];

Define and assign multiple values

Nsarray *array = [Nsarray arraywithobjects:@ "", @ "", nil];

A new method that can either assign multiple values or assign a value

Nsarray *array = @[@ "", @ ""];

Dictionary  

Note: Keys and values appear in pairs

Definition nsdictionary *dictionary = [[Nsdictionary alloc] init];

Definition nsdictionary *dictionary1 = [Nsdictionary dictionary];

Define and assign a key and value nsdictionary *dictionary2 = [nsdictionary dictionarywithobject:@ "value" forkey:@ "key"];

Define and assign multiple keys and values nsdictionary *dictionary3 = [nsdictionary dictionarywithobjectsandkeys:@ "Object", @ "key", @ "Object1", @ "Key1 @ "Object2", @ "Key2", nil];

New method: Nsdictionary *dic1 =

@{@ "Key1": @ "Object1", @ "Key2": @ "Object2", @ "Key3": @ "Object3", @ "Key4": @ "Object4"};

The difference between the values

Array value is the array name and array subscript, such as: array[0], but can not cross, that is, cannot exceed the array.count;array.count array length;

The dictionary value is the function Objectforkey: @ "key";

can also use dictionary[@ "key"];

Another difference is that the dictionary is {value when printing output, value 1; value 2; value 3}, array is (value, value 1, value 2, value 3) or [value, value 1, value 2, value 3]

Variable groups and mutable dictionaries

The variable group cannot use the new method; Nsmutablearray *array = @[@ "", "@" ";

The rest are the same.

Owned method: [Array removeobjectatindex:+]; Remove array subscript to 70 elements

[Array removeobject:@ " skill 7"];// Remove "skill 7 " in array

[Group firstobject];// Gets the first element of the array

[Group lastobject];// gets the last element of the array

[Group Replaceobjectatindex:3 withobject:@ "fengshenghai666"];// replace the third element as fengshenghai666

Variable Dictionaries also cannot use the new method nsmutabledictionary *dic1 =

@{@ "Key1": @ "Object1", @ "Key2": @ "Object2", @ "Key3": @ "Object3", @ "Key4": @ "Object4"};

Two functions

[Dictionary setobject:@ "iphone" forkey:@ "phone"]; Replace or add

[Dictionary removeobjectforkey:@ "Phone"]; Remove key value phone corresponding content

Call notes between an array and a dictionary

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.