Nsarray represents an immutable collection of collection elements, and once Nsarray is successfully created, the program cannot add new elements to the collection, delete old elements, and replace old ones. Nsmultablearray on the contrary, for a set of mutable elements, you can add, delete, and replace elements. What you can do: 1, create arrayWithCapacity2, add elements, start with add 3, delete elements, start with remove 4, replace elements, start with replace 5, sort the collection itself, start with sort (unlike Nsarray, Nsmutable is the ordering of the element collection itself, and Nsarray is a collection of elements that return a new sort completion.
(Note: The following procedures are for reference only, and many methods are not listed.)////MAIN.M
//Nsmultablearray
//
//Created by Mac on 14-12-3.
//Copyright (c)yearsmac. All rights reserved.
//
#import<Foundation/Foundation.h>
voidMultablecreataray ()
{
//CreateMultablearray
Nsmutablearray * Array1 =[Nsmutablearrayarraywithcapacity:Ten];
Nsmutablearray * Array2 =[Nsmutablearrayarraywithobjects:@ "Hello1",@ "Hello2",@ "Hello3",@ "Hello4",Nil];
Nsmutablearray * Array3 =[Nsmutablearrayarraywithobjects:@ "Insert1",@ "Insert2",@ "Insert3",Nil];
//in thearray1add elements in
[Array1 AddObject:@ "Hello1"];
[Array1 AddObject:@ "Hello2"];
[Array2 AddObject:@ "Hello5"];
NSLog(@"%@", array1);
NSLog(@"%@", array2);
[Array1 Addobjectsfromarray: Array2];
NSLog(@"%@", array1);
[Array1 InsertObject:@ "Insert1"Atindex:2];
NSLog(@"%@", array1);
//Delete Element
[Array1 Removeobject:@ "Hello1"];
NSLog(@"%@", array1);
Nsmutablearray *array = [Nsmutablearrayarraywithobjects:@ "One",@ "both",@ "three",@ "Four",Nil];
Nsarray *newadditions = [Nsarrayarraywithobjects:@ "a",@ "B",Nil];
Nsmutableindexset *indexes = [NsmutableindexsetIndexsetwithindex:1];
[Indexes Addindex:3];
[Array insertobjects: Newadditionsatindexes: indexes];
NSLog(@ "Array:%@", array);
}
intMain (intargc, Const Char * argv[]) {
@autoreleasepool {
//Insert code here ...
NSLog(@ "Hello, world!");
Multablecreataray();
}
return 0;}
====>>>>>
2014-12-03 17:32:27.148 nsmultablearray[2527:303] Hello, world!
2014-12-03 17:32:27.151 nsmultablearray[2527:303] (
Hello1,
Hello2
)
2014-12-03 17:32:27.152 nsmultablearray[2527:303] (
Hello1,
Hello2,
Hello3,
Hello4,
Hello5
)
2014-12-03 17:32:27.152 nsmultablearray[2527:303] (
Hello1,
Hello2,
Hello1,
Hello2,
Hello3,
Hello4,
Hello5
)
2014-12-03 17:32:27.153 nsmultablearray[2527:303] (
Hello1,
Hello2,
Insert1,
Hello1,
Hello2,
Hello3,
Hello4,
Hello5
)
2014-12-03 17:32:27.153 nsmultablearray[2527:303] (
Hello2,
Insert1,
Hello2,
Hello3,
Hello4,
Hello5
)
2014-12-03 17:32:27.154 nsmultablearray[2527:303] Array: (
One
A
Both,
B
Three,
Four
)Program ended with exit code:0
"Foundation Frame" Nsmutablearray