Objective-c Arrays and dictionaries

Source: Internet
Author: User

(1) array

nsarray* array = [[Nsarray alloc] initwithobjects:@ "Hello" @ "World", nil]; Only object types can be stored, and the underlying type, such as int, may be converted to a string type and then passed in

(NSString) [Array objectatindex:1]; Remove the first element and return to the string

Note: Nsarray can not be changed, cannot add delete element

(2) Variable group

nsmutablearray* arr = [[Nsmutablearray alloc] init];

[arr AddObject: @ "Hello"];

[Arr removeobject:@ "Hello"];

[Arr removeobjectatindex:0];

[Arr Removeobject:inrange:]

(3) Dictionary

nsdictionary* dic = [nsdictionary dictionarywithobjectsandkeys:@ "Obj1", @ "Key1", @ "Obj2", @ "Key2", nil];

[DiC objectforkey:@ "Key1"];

Note: Nsdictionary and Nsarray are immutable.

(4) Variable dictionary

nsmutabledictionary* dic = [[Nsmutabledictionary alloc] init];

[DiC setobject:@ "Obj1" forkey:@ "Key1"];

Access is the same as nsdictionary.

Objective-c Arrays and dictionaries

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.