How to compare arrays? And change attributes?

前端 未结 3 913
忘掉有多难
忘掉有多难 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:29

    I think you'll have to do a n*n search in this case. Loop through every object in Array1, have a nested loop and compare every item in Array2 to the current object (in Array1). If they are equal then change your attribute.

    for (int i = 0; i < [array1 count]; i++)
        for (int j = 0; j < [array2 count]; j++)
            if ([array1 objectAtIndex:i] == [array2 objectAtIndex:j]) {
                // do yo thangs
            }
    

提交回复
热议问题