Guest User

Untitled

a guest
Aug 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. Objecive-C – Manipulating two arrays
  2. NSMutableArray *web = [[NSMutableArray alloc] initWithObjects:@"2",@"3",@"4",nil];
  3. NSMutableArray *disk = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",nil];
  4.  
  5. - (void)minusSet:(NSSet *)otherSet
  6.  
  7. NSMutableSet *web = [[NSMutableSet alloc] initWithObjects:@"2",@"3",@"4",nil];
  8. NSMutableSet *disk = [[NSMutableSet alloc] initWithObjects:@"1",@"2",@"3",nil];
  9.  
  10. NSMutableSet * remArray = [[NSMutableSet setWithSet:disk] minusSet:web];
  11. NSMutableSet * addArray = [[NSMutableSet setWithSet:web] minusSet:disk];
  12.  
  13. NSMutableArray * remArray = [NSMutableArray arrayWithArray:disk];
  14. [remArray removeObjectsInArray:web];
  15.  
  16. - (NSArray *) differnceBetween: (NSArray *) array1 and: (NSArray *) array2 {
  17. NSMutableArray *difference = [[NSMutableArray alloc] init];
  18. for(id obj in array1) {
  19. if(![array2 contains:obj]) {
  20. [differnce addObject:obj];
  21. }
  22. }
  23. return difference;
  24. }
Add Comment
Please, Sign In to add comment