HurkNburkS
HurkNburkS

Reputation: 5510

Create a unique NSArray from NSSet with out null values

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

Answers (1)

danypata
danypata

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

Related Questions