ios - How to pass variable reference between viewcontrollers? -


i writing application customizable color palette. have settings class (settings) stores these colors, , settings viewcontroller (themevc) lets user modify them, , list possible values (colorsvc).

i keep reference settings in both view controllers:

let settings = settings.sharedinstance 

in themevc list categories background, text , on in tableview this:

let cell = tableview.dequeuereusablecellwithidentifier("right detail disclosure", forindexpath: indexpath) 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 trying pass settings value colorsvc, way copied:

override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject!) {         if (segue.identifier == "showcolorsviewcontroller") {             let detailvc = segue.destinationviewcontroller as! colorsviewcontroller              detailvc.setting = settings.backgroundcolor         }     } 

colorsvc lets user pick color , modifies corresponding value in settings based on row selected in themevc.

how can pass different value every cell receiving colorsvc can read , modify corresponding setting?

i looking inout keyword, sadly couldn't use in scenario.

classes reference types:

unlike value types, reference types not copied when assigned variable or constant, or when passed function. rather copy, reference same existing instance used instead.

in case above think best setting detailvc.setting setting , accessing/modifying object properties on object directly instead of passing value of class property, help?

see classes reference types in documentation

edit:

i believe using colorsvc set color on themevc, segue colorsvc, select color , returned themevc table cell, correct?

if there couple of ways achieve this, think best way pass cell's row colorsvc can update needed.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -