objective c - How to extract unique objects from multiple arrays -


edit:
have 2 different arrays repeated strings , want create new array unique strings.

for instance, take these 2 arrays:

nsarray *array1 = [[nsarray alloc] initwithobjects:@"a",@"b",@"c",nil];  nsarray *array2 = [[nsarray alloc] initwithobjects:@"a",@"d",@"c",nil];  // result should array objects "b", , "d"  // since 2 not repeated in other array. 

edit:

// starting arrays nsarray *array1 = [[nsarray alloc] initwithobjects:@"a",@"b",@"c",nil];  nsarray *array2 = [[nsarray alloc] initwithobjects:@"a",@"d",@"c",nil];  // create 2 new arrays contain objects  // not in other array: nsmutablearray *uniqueelementsinarray1 = [array1 mutablecopy]; [uniqueelementsinarray1 removeobjectsinarray:array2];  nsmutablearray *uniqueelementsinarray2 = [array2 mutablecopy]; [uniqueelementsinarray2 removeobjectsinarray:array1];  // combine 2 arrays. // result contains objects @"b" , @"d": nsarray *result = [uniqueelementsinarray1 arraybyaddingobjectsfromarray:uniqueelementsinarray2]; 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -