Foundation Framework-Collections

Source: Internet
Author: User

First, Nsarray and Nsmutablearray

(i) Nsarray non-variable group

(1) Basic introduction of Nsarray

Nsarray is an array used in OC, is object-oriented, manipulates objects in object-oriented form, and is an immutable group.

A disadvantage of C-language arrays is that only elements of the same data type are stored in arrays.

OC arrays can only hold OC objects, not non-OC objects, such as int, struct, enumeration, and so on.

(2) Creation of Nsarray

(3) Nsarray's visit

(4) Traversal of Nsarray

There are several ways to traverse an array:

First create an array

The first method: use for loop traversal

In-depth study of block traversal:

Each time an element is taken, it is passed to obj, and the block is called once, and the current element and index position are passed as parameters to the block.

Note that the 1:break is only used in two situations, the switch and the loop structure.

Note The 2:stop parameter is used to stop the traversal, and if the value is yes, it stops.

(ii) nsmutablearray variable array

(1) Basic use of Nsmutablearray

Note: Nsmutablearray inherits from Nsarray and almost has all the methods of Nsarray.

Ii. Nsset and Nsmutableset

(i) Nsset immutable collection

Basic use:

(ii) Nsmutableset variable set

Basic use:

(iii) Comparison of Nsset and Nsarray

(1) Common denominator:

1) are all collections and can hold multiple objects

2) Only OC objects can be stored, not non-OC object types (such as int, such as the basic data types and structure, enumeration, etc.).

3) is immutable and has a variable subclass.

(2) different points:

1) Nsarray Order, Nsset no order

Iii. Nsdictionary and Nsmutabledictionary

(i) Nsdictionary immutable dictionary

(1) Introduction

Dictionary in the real world: find specific content based on the index

Nsdictionary in OC: Find value based on key. Everything stored inside is a key-value pair.

(2) Creation of Nsdictionary

Note: The Quick Create dictionary is a compiler attribute.

(3) Nsdictionary's visit

(4) Traversal of nsdictionary

(ii) nsmutabledictionary variable dictionary

(1) Basic use of nsmutabledictionary

(2) Attention to the use of nsmutabledictionary

Note: This quick-create method only works with immutable dictionaries.

Foundation Framework-Collections

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.