I am writing an application with a customizable color palette. I have a settings class (settings) which stores these colors, and a settings viewcontroller (themeVC) which lets the user modify them, and another to list the possible values (colorsVC).
I keep a reference to the settings in both view controllers:
let settings = Settings.sharedInstance
In the themeVC I list categories like background, text and so on in a tableview like this:
let cell = tableView.dequeueReusableCellWithIdentifier("right detail with disclosure", forIndexPath: indexPath) as UITableViewCell
switch indexPath.row {
case 0:
cell.textLabel?.text = "Backgrounds"
cell.detailTextLabel?.text = settings.backgroundColor.name()
case 1:
....
default:
cell.textLabel?.text = "Texts"
cell.detailTextLabel?.text = settings.textColor.name()
}
return cell
I am trying to pass the settings value to the colorsVC, but this way it is just copied:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if (segue.identifier == "showColorsViewController") {
let detailVC = segue.destinationViewController as! ColorsViewController
detailVC.setting = settings.backgroundColor
}
}
ColorsVC lets the user pick a color and then modifies the corresponding value in settings based on which row was selected in themeVC.
How can I pass a different value for every cell so the receiving colorsVC can read AND modify the corresponding setting?
I am looking for something like the inout keyword, but sadly I couldn't use it in this scenario.