I have a OnePresence.swift file and on it I have:
extension OnePresence: XMPPStreamDelegate {
    public func xmppStream(sender: XMPPStream, didReceivePresence presence: XMPPPresence) {
        OpenChatsTableViewController().showAlert(username)
    }
}
In my OpenChatsTableViewController:
func showAlert(username: String) {
    showBuddyRequest(username)
}
And where:
import Foundation
protocol BuddyRequestProtocol {
    func showBuddyRequest(fromUser: String)
}
extension BuddyRequestProtocol where Self: UIViewController {
    func showBuddyRequest(fromUser: String) {
        let alert = UIAlertController(title: "AAA", message: "\(fromUser) wants to add you as a friend.", preferredStyle: UIAlertControllerStyle.Alert)
        alert.addAction(UIAlertAction(title: "Friend Request", style: UIAlertActionStyle.Default, handler: nil))
        self.presentViewController(alert, animated: true, completion: nil)
    }
}
in this case I get the next error:
Warning: Attempt to present <UIAlertController: 0x7c3c4400> on <OpenChatsTableViewController: 0x7b0ecee0> whose view is not in the window hierarchy!
How can I fix this code and rewrite/refactor it?
 
    