How to compare two NSArrays for equal content?

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

    This can be done by using one NSMutableArray.The main point to be remembered is that the larger array should be saved in NSMutableArray. Otherwise it wont work as expected. The code is given below.
    
    NSArray *array1 = [NSArray arrayWithObjects:@"One", @"Two", @"Three", nil];
    NSArray *array2 = [NSArray arrayWithObjects:@"Two", @"Three", @"One", nil];
    NSMutableArray *intermediate = [NSMutableArray arrayWithArray:array1];
    [intermediate removeObjectsInArray:array2];
    NSUInteger difference = [intermediate count];//returns the number of difference between two arrays.
    

提交回复
热议问题