Search code examples
objective-carraysnsmutablearraynsarray

Compare two arrays and remove equal objects


I have a list of words and a list of words specific for an exercise. Users can move words between each list. But there should not be any word duplicates. It works fine until I need to re-fetch the data after saving to an SQL database.


Solution

  • If your goal is to remove from array2 anything that is present in array1, you can:

    [array2 removeObjectsInArray:array1];