Objective-C Programming Summary (Article 5) set type operations

Source: Internet
Author: User

Collection type, including nsarray, nsdictionary, and nsenumerator objects for traversal.

Create an unchangeable array object:

Nsarray * ary = [nsarray arraywithobjects: @ "title", @ "content", [nsnumber numberwithint: 2], nil];

Note that nsarray cannot store basic types such as float, Int, and double. Otherwise, it is set to 0. In addition, the above call must end with nil, which means nil cannot be stored in nsarray.

Traversal of array objects:

Nsenumerator * enu = [ary objectenumerator];

Id OBJ;

While (OBJ = [enu nextobject]) {

If ([OBJ iskindofclass: [nsstring class]) // ismemberof cannot be used here. Because the actual type returned here is _ nscfconstantstring.

{Nslog (@ "% @", OBJ );}

}

Use nsmutablearray to create a variable array. You can also use [ary mutablecopy] to directly return a variable array.

Nsmutablearray * Mary = [ary mutablecopy];

[Mary addobject: @ "This Is The spliter"];

In addition, each array has a componentsjoinedbystring method, which corresponds to componentsseperatedbystring of nsstring.

 

The last is nsdictionary.

[Nsdictionary * DIC = [nsdictionary dictionarywithobjectsandkeys: @ "Lucy", @ "name", [nsnumber numberwithint: 17], @ "Age", nil]; // you also need to end with nil

Nsenumerator * enu = [DIC keyenumerator];

ID key;

While (Key = [enu nextobject]) {

 

 

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.