Q:

Change (UITableView numberOfRowsinSection switch) into smaller, nicer code?

I am populating Persons list in TableView, divided in sections alphabetically. Using Switch case does the job, but i tried to figure out something "loopier" or so for more subtle code, but have not succeeded.
Is there a way to turn this:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // return the number of rows for index letters
    // example: for A there are 2 contacts Alex and Andrea
    // so rows in section for A are 2

    switch (determineKeyList()[section]) {
        case "A": return determineValueCountForKey("A")
        case "B": return determineValueCountForKey("B")
        case "C": return determineValueCountForKey("C")
        case "D": return determineValueCountForKey("D")
        case "E": return determineValueCountForKey("E")
        // every alphabet letter follows..
        default: return 0
    }
}

into something nicer for each case that there is in the database. Plus what if I have nobody in my list, like, under name that starts with "H"? Default return 0? Or I need additional check that skips the letter?
Thanks!

A:

Something along the following likes should work:
if (section > 5) { // E is the 5th letter 
    return 0;
}
return determineValueCountForKey(determineKeyList()[section]);

Instead of the current if-condition you could check also if the returned letter is greater than 'H'.

