Skip to content

Instantly share code, notes, and snippets.

@ethereal-engineer
Created June 9, 2014 09:38
Show Gist options
  • Save ethereal-engineer/19cda0e71bb240242313 to your computer and use it in GitHub Desktop.
Save ethereal-engineer/19cda0e71bb240242313 to your computer and use it in GitHub Desktop.
A bit of swift optimising
// Playground - noun: a place where people can play
import UIKit
var str = "Hello, playground"
var tableSourceArray = [
[
"Name" : "Provider",
"Details" : [ "Chosen Provider:" ]
],[
"Name" : "Support",
"Details" : [ "Email me", "Tweet me", "Love me", "Hate me", "I hate Swift", "Swift must burn"]
]
]
func numberOfSectionsInTableView(tableView: UITableView?) -> Int {
return countElements(tableSourceArray)
}
numberOfSectionsInTableView(nil)
func tableView(tableView: UITableView!, titleForHeaderInSection section: Int) -> String! {
return tableSourceArray[section]["Name"] as String
}
tableView(nil, titleForHeaderInSection: 0)
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
// Rows is the number of entries in the details array of the section dictionary (assumed)
return countElements(tableSourceArray[section]["Details"] as String[])
}
tableView(nil, numberOfRowsInSection: 0)
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "settingsMenuCell")
cell.text = (tableSourceArray[indexPath.section]["Details"] as String[])[indexPath.row]
return cell
}
tableView(nil, cellForRowAtIndexPath: NSIndexPath(forRow: 0, inSection: 0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment