Fabio Berger
Fabio Berger

Reputation: 1917

Group tableView by first character of name

I try to group my UITableView by the first character of the name of the customer. I use MagicalRecords as a helper, because I get my data from a database. What I have looks like this:

self.dataSource.resultsController = [Customer fetchAllGroupedBy:nil withPredicate:nil sortedBy:@"lastName,firstName" ascending:YES delegate:self.dataSource];

I want to replace the fetchAllGroupedBy:nil to somewhat like fetchAllGroupedBy:@"lastName.firstChararcter"

I already tried fetchAllGroupedBy:@"[lastname substringWithRange:[NSMakeRange(0, 1)] but that does not work.

My question now is, is this even possible and if so, how?

Any help appreciated.

Upvotes: 0

Views: 178

Answers (1)

sidslog
sidslog

Reputation: 654

You should add a transient property "firstCharacter" to a Customer entity and group by it. See - this so question and answer

Upvotes: 2

Related Questions