How to compare two NSArrays for equal content?

前端 未结 7 1424
旧巷少年郎
旧巷少年郎 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:20

    I found the solution,,we can achieve that by sorting the array elements

     NSArray *arr1 = [[NSArray alloc]initWithObjects:@"a2223a",@"ab33b",@"a1acdf",@"ac23c45", nil];
        NSArray *arr11 =  [arr1 sortedArrayUsingSelector:@selector(localizedCompare:)];
        NSArray *arr2 = [[NSArray alloc]initWithObjects:@"ab33b",@"ac23c45",@"a1acdf",@"a2223a", nil];
        NSArray *arr22= [arr2 sortedArrayUsingSelector:@selector(localizedCompare:)];
        if([arr11 isEqualToArray:arr22])
        {
            NSLog(@"equal");
        }
        else
        {
            NSLog(@"Not equal");
        }
    

提交回复
热议问题