How to compare arrays? And change attributes?

前端 未结 3 937
忘掉有多难
忘掉有多难 2021-01-21 19:32

I\'m new ios developer, I want to compare and change attributes

Array1 = (object1,object2, object3, object4) Array2 = (object2,object4, object5, object8)

Compare

3条回答
  •  既然无缘
    2021-01-21 20:34

    You can use fast enumeration to pass through array 2, then use containsObject: to check if it belongs to array1:

    for (id object in array2)
    {
        if ([array1 containsObject:object])
        {
            // change your settings here
        }
    

    You could also create a new array using filteredArrayUsingPredicate:, or get the index paths of the matching objects using indexesOfObjectsPassingTest:. You haven't said how many objects are likely to be in your array so I don't know if performance is going to be an issue.

提交回复
热议问题