I'm trying to figure out how to tell if two NSArrays are equal to each other. I looked at apple's documentation for the instance method isEqualToArray: and it had this to say:
This is a problem for me, because the arrays I'm using may contain the exact same objects, but in different order. In my app I have many NSArrays that each contain some NSNumber objects. I would like to compare two arrays to see if they each have the exact same numbers occurring the exact same amount of times, regardless of order.
For example, I have one array with the numbers 5, 1, 3 (in that order). Another array has the numbers 3, 1, 5. I would consider these arrays equal for the purposes in my app because they both are the same, except for order. However, isEqualToArray: does take order into account, so I can't use it.
Could someone suggest a way to tell if my two arrays are the same disregarding the order of the objects? Thanks in advance!
Two arrays have equal contents if they each hold the same number of objects and objects at a given index in each array satisfy the isEqual: test.
This is a problem for me, because the arrays I'm using may contain the exact same objects, but in different order. In my app I have many NSArrays that each contain some NSNumber objects. I would like to compare two arrays to see if they each have the exact same numbers occurring the exact same amount of times, regardless of order.
For example, I have one array with the numbers 5, 1, 3 (in that order). Another array has the numbers 3, 1, 5. I would consider these arrays equal for the purposes in my app because they both are the same, except for order. However, isEqualToArray: does take order into account, so I can't use it.
Could someone suggest a way to tell if my two arrays are the same disregarding the order of the objects? Thanks in advance!