Last active
June 29, 2016 15:57
-
-
Save Broich/ef0a3821f2d7ca753714931597b0bb16 to your computer and use it in GitHub Desktop.
Display NSUserDefaults in a UITableViewController (Swift)
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
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