oc-nsarray-nsmutablearray-array-variable array

Source: Internet
Author: User

oc-nsarray-nsmutablearray-array-variable array

1,oc language and C array differences An array of OC languages can only store object pointers and cannot store basic types

2, creation of arrays

(1), Initwithobjects:initwithobject

(2) @[@ "Jack" ...];

(2), Initwitharray:

(3), Arraywithobjects:arraywithobject

(4), Arraywitharray:

3, Array common methods

(1), gets the number of elements: Count [arr Count] Arr.count

(2), get the element of the corresponding position by index [arr objectatindex:1] arr[1]

(3), get index by object address Indexofobject [arr indexofobject:@ "Jack"]

  (4) to determine if the array contains element Contailsobject:

(5), gets the last element of the array Lastobject:

(6), array elements are stitched into strings

4, the array is traversed for the for Forin Enumblock "Block Method"

Variable group

(1), add an element addobject: [arr addobject:@ "12"];

(2), insert element at specified position InsertObject:atIndex:insertobject

(3), append an array of Addobjectsfromarray:addobjectsfromarray

(4), delete the last element removelastobject remove End Object

(5), delete the element Removeobjectatindex at the specified location:

(6), remove all elements removeallobjects

(7), delete the specified element removeobject:

(8), delete the specified range of elements Removeobject:inrange:

(9), deletes the specified element according to an array Removeobjectsinarray: Deletes an element by the set of elements in the array

(10), modify array SetArray: integer instead of array

(11), replacing the element replaceobjectatindex:withobject at the specified position:

(12), swap array elements Exchangeobjectatindex:withobjectindex:

3, sort of variable group (1), Sortusingselector: (SEL) Comparator

[Muarr Sortusingselector: @sel (method name)];

Determines whether an object is an instance of a class 1,iskindofclass: (Class) AClass Description

1. Print the object's information must override the Description method

What is SEL 1,sel: type Selector

2, how to convert a method into a selector type: @selector and Nsselectformstring (method name)

3, the detection of the method that the selector represents is not implemented in the class that the object pointer belongs to 4, the function of the selector

oc-nsarray-nsmutablearray-array-variable array

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.