How can I get instance of current UIApplication from View Controller in Swift?
I am getting Use of unresolved identifier 'sharedApplication' error with this code:
let app = sharedApplication as UIApplication
                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
                        You can do it by
let app =  UIApplication.sharedApplication()
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With