views:

56

answers:

3

I have 2 NSArray's that are holding values...

For example NSArray 1 has values 1 2 4 in it

and NSArray 2 has values 1 2 4 5 6 in it.

How can I write code to compare these 2 arrays to get the following information...

Count the values that are the same (so in this case 3) and count the values that are not the same (in this case 2).

I am simply populating the arrays like this: NSString *s = @"1,2,4"; NSArray *numbers = [s componentsSeparatedByString:@","];

where *s is actually getting the text from a UITextField. If sorting mattering in comparing can you show me code to sort to make sure the user doesnt put the numbers in order?

A: 

You can take a look at this SO entry, as it contains half of the solution. For the remaining half, you should be able to figure how to do it.

Laurent Etiemble
A: 

If you are fine with sets instead of arrays, you can use NSMutableSet instead of NSArray. NSMutableSet has nice methods like intersectSet: and minusSet:

Diederik Hoogenboom
A: 

I would probably use the following method of the NSArray class:

enumerateObjectsUsingBlock.

and code the block testing for membership in the other array with the method:

indexOfObjectIdenticalTo.

If this isn't clear to you let me know.

ennuikiller
Im not very comfortable with odjective c yet can you write out an example?
Nick LaMarca