Objective-C data set and objective-c set

Source: Internet
Author: User

Objective-C data set and objective-c set

1. NSSet

1. It is an unordered collection class that manages multiple objects. The biggest feature is that duplicate objects are not allowed in the collection, which is similar to the mathematical meaning of the set.

2. Apart from unordered and repeatable features, other functions are the same as those of NSArray.

2. NSArray

1. arrays are a group of Ordered Sets,

2. Obtain each element in the array through index subscript, which is the same as the string,

3. arrays also have NSMutableArray and NSArray ),

4. The basic data type and struct data type cannot be saved in the array. NSNumber and NSValue must be used for data encapsulation.

Code 1:

  

 

Code 2:

Encapsulate a class MyClass and store MyClass with Arrays

  

 

  

 

In main. m:

  

  

Code 3:

  

  

 

  

3. NSMutableArray (variable array)

1. NSMutableArray (variable array)

Is the modifiable array class defined by Objective-C.

Is a subclass of NSArray.

2. Create an array

NSMutableArray * array = [NSMutableArray arrayWithObjects: @ "one", @ "two", @ "three", nil];

   

3. Add Elements

1. Add an object to the end of the array

2. Insert an object at a specified position

   

   

    

4. Delete Elements

Delete Element

1. Last object

[Array removeLastObject];

2. Specify the object

[Array removeObject: @ "two"];

3. Specify the location object

[Array removeObjectAtIndex: 2];

4. Specify a range object

Nsange r = {1, 2 };

[Array removeObjectsInRange: r];

5. Clear the Array

[Array removeAllObjects];

  

  

4. NSDictionary (unchangeable dictionary)

1. To find objects in a set more quickly

2. Use key (key) (name) to specify the value ).

Generally, the key value is of the string type, and the value is of any object type.

3. duplicate key values are not allowed, and the value can be repeated.

4. The value of key and value cannot be blank.

  

  

 

  

  

 

  

  

 

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.