Ben Packard
Ben Packard

Reputation: 26476

Comparing an NSArray of NSStrings with another NSArray of NSStrings

I have two NSArrays each containing NSStrings. I need to test whether the two arrays are equal. In this instance, equality means not that the arrays contain the same objects, but that each object returns true for isEqualToString when compared its counterpart. The arrays are also not equal if one contains more items than the other, or the order of the items is different.

Can I assume isEqualToArray won't help me here?

Similarly, I don't see an approach using NSSet that would fulfill all of the criteria.

How might I test the equality of these two arrays?

Upvotes: 3

Views: 1828

Answers (1)

mipadi
mipadi

Reputation: 410632

The docs for isEqualToArray state:

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.

That seems like it fits your criteria.

Upvotes: 9

Related Questions