title: How to pack customized UIAlertController in one class (swift)?
body: <p>My iOS app requires a customized group of alerts with similar functionality. Can I pack those in a class, so I don't have to copy paste in every UIViewController?</p>
  
  <pre><code>func displayAlert(msg:String, handler: (UIAlertAction) -&gt; Void）{...} 
  func successMsg (msg: String){...}  
  func failMsg(msg: String){...}
  </code></pre>
  
  <p>I was trying to pack them into a subclass(AlertViewController) of UIViewController, but then there was runtime error:"Attempt to present &lt;...UIAlertController...> on &lt;...UIAlertController...> whose view is not in the window hierachy!"</p>
  
  <p>code in myViewController:</p>
  
  <pre><code>@IBAction func leave() {
      let date = getDate()
      let datePresent = dateForPresent()
      if stID == nil || name == nil {
          return
      } else {
          alert.displayAlert("\(datePresent)"){action in
              self.request.getResult(self.request.leavePara(self.stID!, date: date, name: self.name!) ){ (result) in
                  dispatch_async(dispatch_get_main_queue(), {
                      let flag = result["result","out_Flag"].int
                      print(result)
                      let msg = result["result","out_nszRtn"].string!
                      if flag == 0 {
                          self.alert.successMsg(msg){ action in
                              self.performSegueWithIdentifier("personUnwind", sender: self)
                          }
                      }else {
                          self.alert.failMsg(msg)
                      }
                  })
              }
          }
      }
  }
  </code></pre>