-6

I got 2 arrays of strings:

NSArray * current = @[@"1", @"6", @"53"];  
NSArray * new = @[@"1", @"626", @"53", @"13"]; 

I want to get number 6 in array, and numbers 626 and 13 in second array (I want data that is in first array but there is not in second, and conversely)

NSMutableSet * newSet = [NSMutableSet setWithArray:new];
[newSet minusSet:[NSSet setWithArray:current ]];
NSArray * result1 = [NSArray arrayWithSet:newSet];
NSArray * result2 = ?

I not get it, I know that is very simple question, but I have no ideas

2 Answers2

0

// Create arrays of the IDs only

NSArray *notiCloudIDs = [notiCloud valueForKey:@"id"];

NSArray *notiLocIDs = [notiLoc valueForKey:@"id"];

// Turn the arrays into sets and intersect the two sets

NSMutableSet *notiCloudIDsSet = [NSMutableSet setWithArray:notiCloudIDs];

NSMutableSet *notiLocIDsSet = [NSMutableSet setWithArray:notiLocIDs];

[notiCloudIDsSet intersectSet:notiLocIDsSet];

// The IDs that are now in notiCloudIDsSet have been present in both arrays

NSLog(@"Duplicate IDs: %@", notiCloudIDsSet);

This will give you the common elements in the two. You can then delete the common elements from array1.

Khawar Ali
  • 3,462
  • 4
  • 27
  • 55
0

Your code contains a lot of syntax errors. Please post actual code, I understand the issue you are talking about, that's why I'm posting this answer. Please post questions with valid code, else you won't get proper answer (Only get downvotes)

Use the following code:

NSArray *current = @[@"1", @"6", @"53"];
NSArray *newArr  = @[@"1", @"626", @"53", @"13"];


NSMutableSet *newSet = [NSMutableSet setWithArray:newArr];
[newSet minusSet:[NSSet setWithArray:current]];
NSArray * result1 = [NSArray arrayWithObjects:[newSet allObjects],nil];
// result 1 will have 626 and 13

newSet = [NSMutableSet setWithArray:current];
[newSet minusSet:[NSSet setWithArray:newArr]];
NSArray * result2 = [NSArray arrayWithObjects:[newSet allObjects],nil];
// result 2 will have 6
Midhun MP
  • 103,496
  • 31
  • 153
  • 200