0

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:)];
1
  • You need to explain your problem better. What do your data structures look like? You have an array of dictionaries. From your code, it looks like you're trying to build an array from the "stage" entries in each dictionary. Why are you converting it into a set, and then back to an array? Are you trying to use NSSet to get rid or duplicate values? None of the container objects you are using allow nil as entries, so were are your NULL values coming from? Or are you referring to NSNull (which is a special object that serves as a placeholder for a nil.) Commented Nov 17, 2013 at 1:31

1 Answer 1

1

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]];
    }]];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.