Reputation: 12954
I have an NSMutableArray
with NSStrings
for items. Some are blank. What is the quickest way to find and remove the blanks without having to resort to looping, comparing to @"", etc.
Thanks,
Doug
Upvotes: 1
Views: 51
Reputation: 2987
NSMutableArray *test = [[NSMutableArray alloc]initWithObjects:@"",@"",@"test",@"test1", nil];
[test removeObject:@""];
Upvotes: 3
Reputation: 107121
You can use NSPredicate for doing this.
NSArray *myFilteredArray = [yourArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"length > 0"]];
Upvotes: 0
Reputation: 39690
[a filterUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
[evaluatedObject length] != 0;
}]];
Upvotes: 0