Reputation: 5510
I am trying to create an NSArray of sorted unique values excluding NULL values from an array of NSdictionaries I currently have. However I can do everything except remove the NULL values how would I do achieve this?
This is the code I currently have.
NSSet *uniqueAreaSet = [NSSet setWithArray:[tempArray valueForKey:@"stage"]];
NSArray *tempAreaArray = [uniqueAreaSet allObjects];
NSArray *sortedAreaArray = [tempAreaArray sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
Upvotes: 0
Views: 737
Reputation: 10175
For removing the null values (if they are actually NSNull objects) you can use the following:
sortedAreaArray = [sortedAreaArray filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
return ![evaluatedObject isEqual:[NSNull null]];
}]];
Upvotes: 1