title: How to update a global variable in Swift in a function
body: <p>I am learning Swift and have a question about passing global variables into a function to be changed.</p>
  
  <p>If I have a global variable declared like this in a class:</p>
  
  <pre><code>var autoCount = 0
  </code></pre>
  
  <p>Then I want to write some functions to manage updating it like:</p>
  
  <pre><code>func updateAutoCount {
      autoCount += 1
  }
  </code></pre>
  
  <p>Is the above acceptable or should I make the function signature like this even though I'm passing a global variable that is readily available:</p>
  
  <pre><code>func updateAutoCount(autoCount: inout Int)  {
      autoCount += 1
  }
  </code></pre>
  
  <p>BTW, I think autoCount should be a global rather than local variable because I want the scope to be global and want it to retain its value as long as the view is available rather than for the life of a function call.</p>
  
  <p>Thanks</p>