Skip to content

Instantly share code, notes, and snippets.

@YGeorge
Created September 7, 2015 14:14
Show Gist options
  • Save YGeorge/0ebf872e69bda28077b0 to your computer and use it in GitHub Desktop.
Save YGeorge/0ebf872e69bda28077b0 to your computer and use it in GitHub Desktop.
NSMutableArray+YGHelper
[sources removeObjectsWithPredicate:^BOOL(id obj){
LCFTSource *source = (LCFTSource *)obj;
return [self.hiddenSourceIDs containsObject:source.sourceID];
}];
#import <Foundation/Foundation.h>
@interface NSMutableArray (YGHelper)
- (void)removeObjectsWithPredicate:(BOOL (^)(id obj))predicate;
@end
#import "NSMutableArray+YGHelper.h"
@implementation NSMutableArray (YGHelper)
- (void)removeObjectsWithPredicate:(BOOL (^)(id obj))predicate {
if (predicate != nil) {
NSMutableArray *newArray = [[NSMutableArray alloc] initWithCapacity:self.count];
for (id obj in self) {
BOOL shouldRemove = predicate(obj);
if (!shouldRemove) {
[newArray addObject:obj];
}
}
[self setArray:newArray];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment