An array is an ordered set of objects that cannot hold basic data types, only instances (objects) of the class Nsarray *array1=[nsarray arraywithobject:@ "one"];Nsarray *array2=[nsarray arraywithobjects:@ "One", @ "one",
Nil];nsarray *array3=[nsarray Arraywitharray:array2];(2 and 3 point to the same address)Nsarray *array4=[nsarray Arraywithcontentsoffile:path];Nsarray*array5=[[nsarray alloc]initwitharray:@ "one"];
adds an element to the end of the array by adding an object to the arraynsarray *array5 =[array2 arraybyaddingobject:@ "End"];
links the elements in an array with the specified stringNsstring*string1=[array componentsjoinedbystring: ","];
whether the array contains the specified elementBOOL iscontain=[array containsobject:@ "BBB"];
queries the elements of the specified object in the array, (returns index subscript) If this element is not, return NsnotfoundNsinteger index=[array indexofobject:@ "CCC";nsstring *lastobject=[array5 Lastobject];
Initialize, set the number of elements to 5, but you can change theNsmutablearray *mutablearray=[nsmutablearray Arraywithcapacity:5];
add an element to an array[Mutablearray addobject:@ "AAA"];
inserts an element into an array by specifying the subscript[Mutablearray insertobject:@ "CCC" atindex:0];
remove the last element[Mutablearray Removelastobject];
removing the specified element[Mutablearray removeobject:@ "AAA"];
Remove the element that made the subscript[Mutablearray removeobjectatindex:0]
adds an array to the array;[Mutablearray addobjectsfromarray:array100];array100 is a subset of Mutablearray
replaces the specified following table element[Mutablearray replaceobjectatindex:0 withobject:@ "Replace"];
Remove all elements[Mutablearray removeallobjects];
traversal of an arrayIt's best to put the same type in an array
Nsarray *array=[nsarray arraywithobjects:@ "1", @ "11", @ "111"
, @ "1111", @ "11111", nil];
for (int i=0; I<[array count]; i++) {
NSString * Str1=[array OBJECTATINDEX:I];
NSLog (@ "%@", str1);
} (generally not due to poor performance)
For (NSString *string in array)
{NSLog (@ "Found%@,string");}For (ID string in array) {NSLog (@ "found%@,string");an ID is used when an array element type is not determined
Foundation framework--nsarray class, array common operations