How to compare two NSArrays for equal content?

前端 未结 7 1425
旧巷少年郎
旧巷少年郎 2021-02-13 01:58

I have 2 Nsarray where objects of 2 arrays are same may be indexes of the object differs, but it should print both are equal irrespective of there indexes

NSArra         


        
7条回答
  •  野性不改
    2021-02-13 02:27

    Those two arrays are not equal. Two arrays are equal is they both have the same objects in the same order.

    If you want to compare with no regard to order then you need to use two NSSet objects.

    NSSet *set1 = [NSSet setWithArray:arr1];
    NSSet *set2 = [NSSet setWithArray:arr2];
    
    if ([set1 isEqualToSet:set2]) {
        // equal
    }
    

提交回复
热议问题