react-native-navigation的迁移库

NSArray+utils.m 1.1KB

1234567891011121314151617181920212223242526272829303132
  1. #import "NSArray+utils.h"
  2. @implementation NSArray (utils)
  3. - (NSArray *)intersect:(NSArray *)array withPropertyName:(NSString *)propertyName {
  4. NSMutableArray* intersection = [NSMutableArray new];
  5. for (NSObject* object in array) {
  6. NSArray* filteredArray = [self filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"%@ == %@", propertyName, object]];
  7. [intersection addObjectsFromArray:filteredArray];
  8. }
  9. return [NSArray arrayWithArray:intersection];
  10. }
  11. - (NSArray *)difference:(NSArray *)array withPropertyName:(NSString *)propertyName {
  12. NSMutableArray* diff = [NSMutableArray arrayWithArray:self];
  13. NSArray* intersection = [self intersect:array withPropertyName:propertyName];
  14. [diff removeObjectsInArray:intersection];
  15. return [NSArray arrayWithArray:diff];
  16. }
  17. - (NSArray *)mapObjectsUsingBlock:(id (^)(id obj, NSUInteger idx))block {
  18. NSMutableArray *result = [NSMutableArray arrayWithCapacity:[self count]];
  19. [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  20. [result addObject:block(obj, idx)];
  21. }];
  22. return result;
  23. }
  24. @end