0

I setup a PhoneGap application and dug around some of the code. Under AppDelegate there is the following object:

@property (nonatomic, strong) IBOutlet CDVViewController* viewController;

However, further down there is this line:

self.viewController = [[MainViewController alloc] init];

What does that line actually do, as viewController is a CDVViewController object, however it now seems to be saying, or at least converting it to a MainViewController object.

Also MainViewController inherits CDVViewController so whats the point should it not begin as a MainViewController like:

 @property (nonatomic, strong) IBOutlet MainViewController* viewController;
Ben_hawk
  • 2,476
  • 7
  • 34
  • 59

1 Answers1

0

It doesn't begin as @property (nonatomic, strong) IBOutlet MainViewController* viewController so that when self.viewController responds to a message's selector, self.viewController can be either class CDVViewController or MainViewController, depending on which responds to the selector at runtime.

This is called polymorphism. You can take a look at this or this.

Community
  • 1
  • 1
yeesterbunny
  • 1,847
  • 2
  • 13
  • 17
  • How would I then set a property of MainViewController using self.viewController, currently trying self.viewController.token = @"hello", results in an error saying self.viewController is a CDVViewObject and so no such property exists :S – Ben_hawk Oct 16 '12 at 09:20
  • If you look at CDVViewObject's property, I assume there's no "token" declared. The power of polymorphism is in the implementation of functions, and how they behave at runtime. – yeesterbunny Oct 16 '12 at 09:59