vivek takrani
vivek takrani

Reputation: 4010

Cannot access AppDelegate

Getting an Error on this line

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate

Could not cast value of type 'LLAppDelegateProxy' (0x2bd218) to 'MyAppName.AppDelegate' (0x2bc708).

I was setting a RootViewController in AppDelegate's didFinishLaunchingWithOptions method which suddenly stopped working. Any help will be appreciated. Thanks in advance.

Upvotes: 1

Views: 545

Answers (1)

deRonbrown
deRonbrown

Reputation: 645

It is possible get access to the original AppDelegate using automatic integration. Add the following static var to your AppDelegate class:

class AppDelegate: UIResponder, UIApplicationDelegate {
    static var originalAppDelegate:AppDelegate!

Next, set that variable at the beginning of didFinishLaunchingWithOptions:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    AppDelegate.originalAppDelegate = self

Now anytime you want access to your original AppDelegate you can retrieve it like so:

AppDelegate.originalAppDelegate.someMethod()

Upvotes: 2

Related Questions