title: Swift function can be called only once
body: <p>What is the simplest way to write a piece of code that can be executed only once?</p>
  
  <p>I know a way but has a problem.</p>
  
  <p>first, I write a Boolean variable that has negative value but can be set to positive and cannot change after that</p>
  
  <pre><code> var hasTheFunctionCalled : Bool = false {
     didSet{
         hasTheFunctionCalled = true
     }
  } 
  </code></pre>
  
  <p>and then write the function and the code inside it:</p>
  
  <pre><code>func theFunction(){
     if !hasTheFunctionCalled{
        //do the thing
     }
     hasTheFunctionCalled = true
   } 
  </code></pre>
  
  <p>but the problem is that the variable can be changed from somewhere else in the scope and this solution doesn't really look so simple and concrete.</p>