matthew
matthew

Reputation: 477

When creating a property for an instance of a viewController, the viewController cannot be found

I am trying to create a property for an instance of a viewController, like so,

@property (strong, nonatomic) DetailsViewController *videoViewController;

but I get an error saying that:

DetailsViewController is an unknown type name

The view controller is definitely imported like so,

#import "DetailsViewController.h"

Why is this happening?

Upvotes: 0

Views: 101

Answers (1)

Bilal Saifudeen
Bilal Saifudeen

Reputation: 1677

To avoid Circular imports, always write Import statements in .m file, and use forward declaration in .h file.

In .h file

@class DetailsViewController;

In .m file

#import "DetailsViewController.h"

OR

For private properties, use Objective - C extensions, i.e,

Im .m file

#import "DetailsViewController.h"

@interface MasterViewController ()<YourProtocolList>

@property(nonatomic, strong) DetailsViewController *detailViewController;

@end


@implementation MasterViewController
//Your implementation stuff
@end

In case of inheritance, you may need to import in .h file.

Upvotes: 1

Related Questions