Created
June 9, 2014 09:38
-
-
Save ethereal-engineer/19cda0e71bb240242313 to your computer and use it in GitHub Desktop.
A bit of swift optimising
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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