vlad5ss vlad5ss - 4 years ago 90
Objective-C Question

How to know if new element added to NSArray

I have a massive

array=["1","2","3","4","5","6"]
, with time.

For example: it would be
array=["1","2","3","4","5","6","10","11"]
.

How to know that two elements added to massive? in the example, new elements added are 10 and 11.

Answer Source

So basically you just need to remove the old elements and show the new elements.

You can try by using removeOjbectsInArray method of NSMutableArray

i.e.
NSArray *oldArray = @[@"1",@"2",@"3",@"4",@"5",@"6"];
NSArray *newArray = @[@"1",@"2",@"3",@"4",@"5",@"6",@"10",@"11"];
NSMutableArray *result = [newArray mutableCopy]; // make sure you make it a mutable copy
// remove the existing elements
[result removeObjectsInArray:oldArray];
NSLog(@"remaining entry: %@",result);

Output

@[10,11];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download