EDIT Swift 4.x
let app = UIApplication.shared.delegate as! AppDelegate
If you're e.g. not in a ViewController, you must:
import UIKit
Perhaps try:
let app = UIApplication.sharedApplication()
EDIT (Swift 3):
It should be noted that in Swift 3, to accomplish this, you will want to access the shared
property instead:
let app = UIApplication.shared
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…