Array of elements to be removed nsmutablearray *filteredarray = [[Nsmutablearray alloc]initwithobjects:@ "1", @ "4", nil]; Array required to be filtered nsmutablearray *dataarray = [[Nsmutablearray alloc]initwithobjects:@ "1", @ "2", @ "1", @ "4", @ "6", @ "1", @ "1", @ " 4 ", @" 1 ", @" 6 ", @" 4 ", 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 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); /* Results: Reslut Filtered array = (2, 6, 6)/*/* Method Two: Iterate through the array, 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:[dataarray objectatindex:i]]) {[DataArray removeobjectatindex:i]; }} NSLog (@ "Data Array =%@", DataArray); /* Result: Data Array = (2, 6, 6) */
ios-filter elements within an array