"expression type is ambiguous without additional context" - reference to appDelegate

I have mine appDelegate

, originally written in Obj-C. I am trying to access it in a new Swift class, but I am getting a weird error that I think is misleading and I am trying to get to the root.

In my Swift file, I set a breakpoint after:

var appDelegate = UIApplication.sharedApplication().delegate

      

If I just po:

po appDelegate

      

I get:

Printing description of appDelegate:
Optional(<AppDelegate: 0x7f81a2d1cc40>)

      

Everything is good.

However, when I try:

po appDelegate.navigationController

      

in the debug console:

error: <EXPR>:1:13: error: type of expression is ambiguous without more context

      

And navigationController is an appDelegate property declared in the original appDelegate.h Obj-C file.


Here's my original SO question: Can't call "..." with an argument list like "..."


EDIT

Based on @ Martin's comment, I changed my code to:

  var appDelegate = UIApplication.sharedApplication().delegate!
  appDelegate.navigationController.popViewControllerIsAnimated(true)

      

Which is now causing the error:

'UIApplicationDelegate' does not have a member named 'navigationController'

      

However, here's my Obj-C AppDelegate.h:

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (nonatomic,strong) VUNavigationController *navigationController;

@property (nonatomic,strong) UIWindow *window;

@end

      

+3


source to share


1 answer


The method is delegate

UIApplication

declared as

unowned(unsafe) var delegate: UIApplicationDelegate?

      



You need to pass the return value to a specific type of application delegate:

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

      

+3


source







All Articles