Swift - Populating TableViews with multiple sections from multidimensional array
<p>I am a beginner in Swift and have managed to understand at least the very basics of how to populate a UITableView. I am stuck now at populating multiple sections with data provided out of a dictionary.</p>

<p>I have a multidimensional Dictionary that assigns Objects to Categories:</p>

<pre class="lang-js prettyprint-override"><code>var categoryDict:[String:[AnyObject]] = ["Category A": ["Object 1","Object 2"], "Category B":["Object 3"]]
</code></pre>

<p>Now I want to populate my TableView, so that it shows something like this:</p>

<ul>
<li><p>Category A</p>

<ul>
<li>Object 1</li>
<li>Object 2</li>
</ul></li>
<li><p>Category B</p>

<ul>
<li>Object 3</li>
</ul></li>
</ul>

<p>So far I am able to create an array of categories to return the number of sections as well as to count the arrays stored in the dictionary to get the number of rows in each specific category. Now I am completely stuck at populating the TableView with sections and rows. How can I do this? Thank you very much!</p>

<p>My code so far:</p>

<pre class="lang-js prettyprint-override"><code>var categoryList:[String] = [String]()
var categoryDict:[String:[AnyObject]] = ["Category A": ["Object 1","Object 2"], "Category B":["Object 3"]]


func getLists() {
    categoryList = Array(categoryDict.keys)
    categoryList.sortInPlace(before)
}

// Sort Array
func before(value1: String, value2: String) -&gt; Bool {
    return value1 &lt; value2;
}

func getNumberOfEntrysInSection (Section: Int) -&gt; Int {

    let category:String = categoryList[Section]    //Get Category for Index in CategoryList

    let value:[AnyObject] = categoryDict[category]! //Get Value for this specific Category

    let number = value.count

    return number
}


// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
    getLists()
    return categoryList.count
}


override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
    return getNumberOfEntrysInSection(section)
}


override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -&gt; String? {
    return categoryList[section]
}


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {

    let cell = tableView.dequeueReusableCellWithIdentifier("BufferCell", forIndexPath: indexPath)

    ???
    return cell
}
</code></pre>