1

I have a set of core data items that I want to sort based on a numeric attribute that I have set to Integer 16. It's just a list of things that have a custom sort so I've added an 'ordering' integer so that I can say abc->1 cba->2 aaa->3 etc. I want to sort using the 1,2,3 and display the key (which is another attribute).

I can't figure out how to do this, I'm guessing I need to change the selector but I don't know what to do.

request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"ordering" ascending:YES selector:@selector(localizedStandardCompare:)]];

The error I get is

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber localizedStandardCompare:]: unrecognized selector sent to instance 0x8142450'

I am creating the core data attribute like this:

dataItemOne.ordering = [NSNumber numberWithInteger:1];

1 Answer 1

5

Wouldn't

request.sortDescriptors = [NSArray arrayWithObject:
    [NSSortDescriptor sortDescriptorWithKey:@"ordering" 
                                  ascending:YES]];

do the job?

Sign up to request clarification or add additional context in comments.

1 Comment

Haha yes it works with that now, I'm sure I tried that before and it didn't work but I think I was getting another error. Brain dead today. Thanks for the help.

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.