Q:

How to pass variable reference between viewcontrollers?

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.

A:

Classes are reference types:

Unlike value types, reference types are not copied when they are assigned to a variable or constant, or when they are passed to a function. Rather than a copy, a reference to the same existing instance is used instead.

In the case above I think you would be best setting detailVC.setting to setting and then accessing/modifying the object properties on the object directly instead of passing the value of a class property, Does this help?
See Classes are Reference Types in the documentation
EDIT:
I believe you are using the colorsVC to set a color on the themeVC, so you segue to the colorsVC, select a color and this is returned to the themeVC table cell, correct?
If so there are a couple of ways to achieve this, I think the best way would be to pass the cell's row to the colorsVC so that it can update it as needed.

