I’m new to iOS and objective C and am trying to come up with things I can do to experiment and teach myself. I’d also like to learn to do things the right way, which can be difficult while learning on your own.
I’d like to take 2 NSArray’s that might look like
Array1:
– Object1: @”Hello”
– Object2: @”This”
– Object3: @”Is a”
– Object4: @”Test”
Array2:
– Object1: @”Hello”
– Object2: @”Is a”
and create a third array that contains those objects that didn’t appear in both array’s that I’ve compared, so the result would be
Array3:
– Object1: @”This”
– Object2: @”Test”
I figured I could run through each array and run through each object with a foreach that would compare each object to the list of objects in the second array, adding array1’s object to array3 if it’s not found.
I’m new to memory management (I know ARC is here but I’m trying to be old school for now, everywhere I look says it’s an important skill to learn) so I’m just trying to find out if there’s a better way to do this.
thanks in advance for any help, cheers
You probably want to operate with sets.
Symmetric difference in Objective C:
The reason why you should use sets for your task is because sets contain unique objects (i.e. they can’t contain two
@"42"NSStringobjects), and this is preferable when you need operations like intersection or difference or union.