Objective-c data collection

Source: Internet
Author: User

1, Nsset

1. is an unordered collection class that manages multiple objects, with the greatest feature being that duplicate objects are not allowed in the collection, and that the mathematical set meanings are the same

2. Other functions and Nsarray are the same except for disorder and no repetition

2, Nsarray

1. An array is a set of ordered sets,

2. The index is indexed to each element in the array, as the string,

3. Arrays also have variable groups (Nsmutablearray) and non-variable groups (Nsarray),

4. Cannot save basic data type, struct data type in array, need to use NSNumber and nsvalue for data encapsulation

Code Listing 1:

  

Code Listing 2:

Encapsulates a class MyClass, stored with an array myclass

  

  

In the MAIN.M:

  

  

Code Listing 3:

  

  

  

3, Nsmutablearray (variable group)

1.NSMutableArray (variable group)

is a modifiable array class defined by objective-c

It's a subclass of Nsarray.

2. Creating an array

nsmutablearray* Array=[nsmutablearray arraywithobjects:@ "One", @ "one", @ "three", nil];

   

3. Adding elements

1. Adding an object at the end of the array

2. Inserting an object at a specified location

   

   

    

4. Deleting elements

Delete Element

1. Last Object

[Array Removelastobject];

2. Specifying objects

[Array removeobject:@ ""];

3. Specify the Location object

[Array removeobjectatindex:2];

4. Specifying a Range object

Nsrange r = {1, 2};

[Array removeobjectsinrange:r];

5. Emptying the array

[Array removeallobjects];

  

  

4. Nsdictionary (Immutable dictionary)

1. To find objects in the collection faster

2. By key (key) (name), the corresponding value (value).

Typically, the value of a key is a string type, and value is any object type

3.key values are not allowed to be duplicated, value values can be duplicated

4. The value of key and value is not allowed to be null

  

  

  

  

  

  

Objective-c data collection

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.