Go directly to the code! 1. You can create a new array that iterates over the array that needs to be removed, and if the new array does not contain an array, add the element if it is included.
1Nsmutablearray *array = [Nsmutablearray arraywithobjects:@"1",@"2",@"2",@"4",@"5",@"6",@"7",@"8",@"9",@"0", nil];2 3Nsmutablearray *New=[Nsmutablearray array];4 for(inti =0; I<[array Count]; i++) {5 6 if([NewContainsobject:[array Objectatindex:i]] = =NO) {7[NewAddobject:[array Objectatindex:i]];8 }9 }TenNSLog (@"%@",New);
Print Result: (1,
2,
4,
5,
6,
7,
8,
9,
0) 2. You can also use Nsset to go to the weight, but this method cannot be reordered, so the de-weight result is confusing code as follows
Nsmutablearray *array = [Nsmutablearray arraywithobjects:@"1",@"2",@"2",@"4",@"5",@"6",@"7",@"8",@"9",@"0", nil]; Nsset*Set=[Nsset Setwitharray:array]; NSLog (@"%@",[Setallobjects]);
Printing results: (
7,
8,
4,
0,
9,
5,
1,
6,
2)
Nsarray Removing duplicate elements