title: How to show alert in all controllers without repeating the code?
body: <p>I want to write one function <code>alert()</code> and to run it. But I want to show this alert in any controllers without repeating the code.</p>
  
  <p>For example: I have Presence.swift class and here I have some condition, as:</p>
  
  <pre><code>if myVar == 1 { // Just for presenting
      runMyAlert()
  }
  </code></pre>
  
  <p>and when in the background <code>myVar == 1</code> user, regardless of the fact that where he is, on which screen, he gets alert on screen.</p>
  
  <p>How can I do it without repeating my code? I tried to make it in AppDelegate as:</p>
  
  <pre><code>func alert(title : String,message : String,buttonTitle : String,window: UIWindow){
      let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
      alert.addAction(UIAlertAction(title: buttonTitle, style: UIAlertActionStyle.Default, handler: nil))
      window.rootViewController?.presentViewController(alert, animated: true, completion: nil)
  }
  </code></pre>
  
  <p>And call it as:</p>
  
  <pre><code>if myVar == 1 {
      AppDelegate().alert()
  }
  </code></pre>