swift access appdelegate from viewcontroller

Swift
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let aVariable = appDelegate.someVariable
func appDelegate() -> AppDelegate {
    return UIApplication.shared.delegate as! AppDelegate
}

Source

Also in Swift: