cs193p – Assignment #3 Extra Task #3

Please note, this blog entry is from a previous course. You might want to check out the current one.

Include the ability to sort the scores shown in the Extra Credit above by last played, score or game duration.

Adjust the layout and add three buttons:

cs193p – assignment #3 extra task #3 – sorting
cs193p – assignment #3 extra task #3 – sorting


Create actions for the buttons which sort the results array using the sorting methods from last task:

- (IBAction)sortByDate {
    self.scores = [self.scores sortedArrayUsingSelector:@selector(compareDate:)];
    [self updateUI];
}

- (IBAction)sortByScore {
    self.scores = [self.scores sortedArrayUsingSelector:@selector(compareScore:)];
    [self updateUI];
}

- (IBAction)sortByDuration {
    self.scores = [self.scores sortedArrayUsingSelector:@selector(compareDuration:)];
    [self updateUI];
}

The first one is new (comparing dates) and needs to be added to the model (don’t forget to make it publicly available in the header file, too):

- (NSComparisonResult)compareDate:(GameResult *)result
{
    return [self.end compare:result.end];
}

Note the sorting methods sort in ascending order, if you want the other way around, you need to adjust them 😉

The complete code is available on github.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

2 thoughts on “cs193p – Assignment #3 Extra Task #3”

Leave a Reply

Your email address will not be published.