NSMutableSet *intersection = [NSMutableSet setWithArray:newsmall];
//this shows an array of newsmall as expected
NSLog(@"intersection %@", intersection);
[intersection intersectSet:[NSSet setWithArray:newnewbig]];
//this shows nothing
NSLog(@"intersection %@", intersection);
//this shows an array of newnewbig as expected
NSLog(@"newnewbig %@", newnewbig);
NSArray *arrayfour = [intersection allObjects];
//this shows nothing
NSLog(@"arrayfour %@", arrayfour);
newsmall and newnewbig have some matched strings, so I expect arrayfour to show a couple of strings.
What did I do wrong?
The problem is in your understanding of how
intersectSetworks.I think you are expecting it to compare contents of the strings from newsmall and newnewbig, but what it’s really doing is comparing object addresses.
Do this before you do the
intersectSetcall:intersectSetwill only work if the address (the%pin the formatting up there) matches. The string contents might match, but what intersectSet cares about is the string address.So really, your solution is that you need to do a different way of comparing strings between sets.