More or less. These lines in .h declare the existence of two public variables called a window and a controller:
@property (strong, nonatomic) UIWindow window; @property (strong, nonatomic) ViewController controller;
But these lines only declare the existence of variables; they actually do not create them. It is up to the class to implement them, but he wants to - they can be virtual variables, for example, which actually do not exist, but calls to methods that create data programmatically or load them from the database or something like that.
These lines in the .m file actually create (โsynthesizeโ) the variables.
@synthesize window = _window; @synthesize viewController = _viewController;
In fact, these lines say that the name of the internal variable is _window, but the public name of the variable is the window. This means that inside the class you can access the variable directly by saying
_window = something;
But outwardly you have to access it using
appDelegate.window = something;
Because it is a public name. You can also access it inside the class using self.window.
Another interesting fact about Objective-C is that using the point syntax to access variables in this way is just a convenient way to call the setter and getter methods to access them. Thus, the synthesized string, in addition to creating a variable named _window, also defines the following two methods:
- (void)setWindow:(UIWindow *)window;
And you can call these methods directly if you want, using
[self setWindow:someValue]; UIWindow *window = [self window];