Skip to content

Instantly share code, notes, and snippets.

@Broich
Last active June 29, 2016 15:57
Show Gist options
  • Save Broich/ef0a3821f2d7ca753714931597b0bb16 to your computer and use it in GitHub Desktop.
Save Broich/ef0a3821f2d7ca753714931597b0bb16 to your computer and use it in GitHub Desktop.
Display NSUserDefaults in a UITableViewController (Swift)
class DebugUserDefaultsViewController: UITableViewController {
var userDefaults = NSUserDefaults.standardUserDefaults().dictionaryRepresentation() as NSDictionary
override func viewDidLoad() {
super.viewDidLoad()
title = "NSUserDefaults"
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return userDefaults.allKeys.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("UserDefaultsCell", forIndexPath: indexPath)
cell.textLabel?.text = userDefaults.allKeys[indexPath.row] as? Swift.String ?? ""
cell.detailTextLabel?.text = String(userDefaults.allValues[indexPath.row])
return cell
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment