0

I have an NSMutableArray containing abbreviated days of the week, sun, mon, tue, wed, thu, fri, sat. I am trying to sort it so that they will always be in this order, no matter which days are there, and/or their current order. How do I sort the string so that they are always in the right order?

I tried using

    NSArray* sorted = [parent.medication.days sortedArrayUsingComparator:^NSComparisonResult(NSString* obj1, NSString* obj2) {

        // sort by position of id string in order array..
        NSUInteger obj1Pos = [idsInOrder indexOfObject:obj1[@"sun"] ];
        NSUInteger obj2Pos = [idsInOrder indexOfObject:obj2[@"mon"] ];

        return [[NSNumber numberWithInteger:obj1Pos] compare:[NSNumber numberWithInteger:obj2Pos]];
    }];

But all that did was throw errors on me, and it didn't even include all 7 days.

1 Answer 1

1

Just remove [@"sun"] and [@"mon"] from the lines where you call indexOfObject:.

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.