"Objective-c Study record" 23rd Day

Source: Internet
Author: User
Tags delete key

Array Class :

Ordered collection

Not variable

An array in OC is a container that can manage a series of elements in an orderly manner , with different element types, but must be object types.

Initialization Method :

1.initWithObjects:

2. Convenience Builder

3. Literal.

1 nsarray *array = @[@ "SF"@ "QOP"@ " ST " @" PANDA "];

Original (Core) method :

1.count. Number of elements in an array

2.objectAtIndex. Get array elements by subscript

Common Methods :

1.containsObjects:. Determines whether an element is contained in an array, returns a Boolean value

2.indexOfObject:. Gets the subscript of the element in the array, based on the element, and returns Nsuinteger

3.componentsSeparatedByString:. This method is called by a string object , splits the string as a separator, and returns the substring to the array

4.componetsJoinedByString:. This method is called by the array object , joins the element in the array as a connector, and returns the concatenated string

variable :

Initialization Method :

1.initWithCapacity:. Like a mutable string, a parameter allocates space because the variable array itself can be resized, so the array depends on the situation

2. Convenience Builder

3. Literal

1 nsmutablearray *array = [@[@"ES"@"VS"@ " NA " @" CM "] Mutablecopy];

This way can also be initialized for variable strings, Mutablecopy is the protocol method in the Mutablecopywithzone: The return value, specifically what is not very clear, the API so write

Common Methods :

1.addObject:. Adding elements to a mutable array

2.insertobject:atindex:. Inserts a new element into the variable array at the specified position

3. Remove the element:

A.removeobject:. parameter is the object name

B.removeobjectatindex:. Delete an element based on an incoming subscript

C.removelastobject:. Delete the last element in an array

D.removeallobjects:. Delete all elements in an array

4.replaceobjectatindex:withobject:. Replace the element to which the first parameter is indexed with the second argument

5.exchangeobjectatindex:withobjectatindex:. Exchange two elements according to subscript

Dictionary class :

Unordered collection, each object is a pair of key-value pairs, by key access element ,key and value must be the object type .

Not variable

Initialization Method :

1.initWithObjectsAndKeys:

2. Convenience Builder

3. Literal

1 nsdictionary *dict = @{@ "Key1": @ "value1", @ "Key2": @ "value2" @ "Key3": @ "Value3" @ "Key4": @ "Value4" };

It is important to note that the convenience constructor as well as the Init method are the values in the previous key after , and the literal is the key before the value .

Common Methods :

1.count. Gets the number of key-value pairs in the dictionary

2.allKeys. Gets all the key values returned to an array

3.allValues. Gets all the values returned to an array

4.objectForKey:. Gets a value in the dictionary by key

Variable

Initialization Method :

1.initWithCapacity:. parameter is the allocated capacity

2. Convenience Builder

3. Literal

1Nsmutabledictionary *mdict = [@{@"Key1":@"value1",@"Key2":@"value2",@"Key3":@"Value3",@"Key4":@"Value4"} Mutablecopy];

Common Methods :

1.setobject:forkey:. Increase key-value pairs

2.removeObjectForkey:. Delete key value pairs according to key

3.removeAllObjects:. Remove all key-value pairs

4.setobject:forkey:. Modify the key-value pairs and add the key-value pairs as well, if the key already exists then modify it, and the new one does not exist

---------to Be Continued---------

"Objective-c Study record" 23rd Day

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.