title: Swift - change variable in another view controller, without knowing the class name?
body: <p>Let's say I have a function in viewController1, that changes a variable in whichever view controller the function is called from (in this case viewController2)</p>
  
  <p>What I've been attempting - </p>
  
  <p>declaring the function in viewController1:</p>
  
  <pre><code>func changeVariable(controller: UIViewController) {
      controller.variable = "Hello"
  }
  </code></pre>
  
  <p>calling the function from viewController2:</p>
  
  <pre><code>changeVariable(self)
  </code></pre>
  
  <p>However, this gives me an error when declaring the function, telling me that UIViewController has no member named 'variable'.</p>
  
  <p>If I then change the function to:</p>
  
  <pre><code>func changeVariable() {
      viewController2.variable = "Hello"
  }
  </code></pre>
  
  <p>It works. But, I don't know which view controller is calling the function beforehand (it could be viewController3, for example), so I can't explicitly state that in the function. </p>
  
  <p>Does anyone know how I can make this work?</p>
  
  <p>Thanks a bunch.</p>