ios-filter elements within an array//inside the DataArray, the elements that are in DataArray and within the Filteredarray array are filtered out//the array of elements that need to be removed Nsmutablea Rray *filteredarray = [[Nsmutablearray alloc]initwithobjects:@ "1", @ "3", @ "9", nil]; Array required to be filtered nsmutablearray *dataarray = [[Nsmutablearray alloc]initwithobjects:@ "1", @ "2", @ "3", @ "1", @ "1", @ "3", @ "1", @ " 5 ", @" 7 ", nil]; /* Method One: Use Nspredicate Note: Nspredicate belongs to the cocoa Framework, in the password, user name and other regular judgments used. Similar to the SQL statement not the self represents the string itself in the in range operator then the not (itself in%@) means: Not the value of the string specified here */ Nspredicate * filterpredicate = [nspredicate predicatewithformat:@ ' not ' (self in%@) ", Filteredarray]; Filter array Nsarray * Reslutfilteredarray = [DataArray filteredarrayusingpredicate:filterpredicate]; NSLog (@ "Reslut Filtered Array =%@", Reslutfilteredarray); /* Method Two: Iterate the array from backward, then match delete */int i = (int) [DataArray count]-1; for (; I >= 0;i--) {//containsobject Determines whether the element exists in the array (as determined by the memory address of the two: YES differs: NO) if ([Filteredarray containsobject:[dataa Rray objectatindex:i]) {[DataArray removeobjectatindex:i]; }} NSLog (@ "Data Array =%@", DataArray);
IOS Nsarray Array filtering