0

My app name is PropertiesSearch so the project contains the following files:

PropertiesSearchAppDelegate.h
PropertiesSearchAppDelegate.m
PropertiesSearchViewController.h
PropertiesSearchViewController.m

I declared an instance variable (ListingNav) in PropertiesSearchAppDelegate.h like this:

#import <UIKit/UIKit.h>

@class PropertiesSearchViewController;

@interface PropertiesSearchAppDelegate : NSObject <UIApplicationDelegate> {
    UINavigationController *ListingNav;
}

@property (nonatomic, retain) UINavigationController *ListingNav;

@end

and in PropertiesSearchAppDelegate.m, I added

@synthesize ListingNav; 

Now I'm trying to access ListingNav from PropertiesSearchViewController.m like this:

PropertiesSearchAppDelegate *appDelegate = (PropertiesSearchAppDelegate *)[[UIApplication sharedApplication] delegate];
// Then here I can easily do appDelegate.ListingNav etc...

But debugger is showing:

Use of undeclared identifier PropertiesSearchAppDelegate

Should I import PropertiesSearchAppDelegate.h in PropertiesSearchViewController.h ?

Thx in advance for your help

Stephane

EmptyStack
  • 51,274
  • 23
  • 147
  • 178
Stephane
  • 4,978
  • 9
  • 51
  • 86

1 Answers1

3

You have to import PropertiesSearchAppDelegate.h in PropertiesSearchViewController.h.

To let a class know about another class, you should either import the class or add @class directive. Adding @class directive just lets the class aware that another class exists. In your case, you should import PropertiesSearchAppDelegate as you are trying to access the members of the class.

EmptyStack
  • 51,274
  • 23
  • 147
  • 178