Nsarray
Foundation Array (Nsarray) is an ordered collection of objects
Nsarrayintfloat compatible, Span style= "font:11.0px ' Heiti sC light ';" > so in Objective-c program, array to store the base data type
Nsarray? Once created, it is no longer possible to make changes to it , and if you want to add, delete, change the array, you need to use Nsarray subclass Nsmutablearray To create the object
Nsarray Common Methods
+arraywithobjects: Use a set of objects to create? An array (note : 1, the method can receive a variable number of arguments.) 2, last? A value specified as nil, indicating the end of the parameter list )
-objectatindex: retrieving elements in an array with an array index
-count: Returns the number of array elements
Nsmutablearray
Nsmutablearray is a subclass of Nsarray, inheriting the
Nsarray all methods , and adds a new method
Nsmutablearray used to handle mutable arrays
+arraywithcapacity: specifying initial capacity for variable arrays
-addobject: Add to the end of a mutable array? An element
-addobjectsfromarray: Add all the elements of an array to the array that called the method
-insertobject:atindex: Add an element to an array-specified bit position
-removeobjectatindex: moves an element in the specified position in the divisor group
-removeobject: Assigning an element in the divisor group
Fast traversal
for (class name * Object Name in the object to traverse )
{
//. . .
}
//
Main.m
Shiyueshihaoshuzu
//
Created by the iphone on 11-10-10.
Copyright year __mycompanyname__. Allrights reserved.
//
#import <Foundation/Foundation.h>
int main (int argc,const char * argv[])
{
@autoreleasepool {
NSAutoreleasePool* Pool=[[nsautoreleasepoolalloc]init];
Insert Codehere ...
nsarray *array=[nsarrayarraywithobjects: @ "one" ,@ "and" ,@ "no" ,nil];// Create an array, Nil Indicates the end of the argument list
NSLog (@ "%@", array);
Nsarray * arr=[nsarrayarraywithobjects:@ "Hello",nil];
NSLog (@ "%@", arr);
ID rr=[array objectatindex:1]; retrieving elements in an array with an array index
NSLog (@ "id%@", RR);
longint I=[arraycount]; The number of elements in the//output array
NSLog (@ "%ld", I);
[nsmutablearrayarraywithcapacity:]; Allocating memory space
Nsmutablearray*nsarr=[nsmutablearrayarraywithobjects:@ "HI",@ "Hello",Nil];
[Nsarraddobject:@ "No"];//-addobject: Add to the end of a mutable array? An element
NSLog (@ "%@", Nsarr);
Nsmutablearray*nsarr2=[nsmutablearray arraywithobjects:@ "A",@ "B",Nil];
[NsarrAddobjectsfromarray: Nsarr2];//-addobjectsfromarray: Add all the elements of an array to the array that called the method, Adds the contents of an array to another array
NSLog(@ "---------%@", Nsarr);
[Nsarr2 insertobject:@ "C" atindex:1];
NSLog (@ "%@", nsarr2);
[Nsarr2removeobjectatindex:0];//-removeobjectatindex: removes the element at the specified position in the divisor group
NSLog (@ "%@", nsarr2);
[Nsarr2removeobject:@ ' B '];//-removeobjectatindex: removes the element at the specified position in the divisor group
NSLog (@ "%@", nsarr2);
For (NSString * tem in Array)// traversal
{
NSLog (@ "tem is:%@", tem); elements inside the output array
}
NSLog(@ "--------------------");
for (inti=0;i<[arraycount];i++)// similar to C inside
{
NSLog (@ "%@", [arrayobjectatindex:i]);
}
//}
[Pool drain];
return 0;
}//
Nsarray----Nsmutablearray