Where and how to declare the view iVar?


#1

By the end of Chapter 6 we end up declaring an instance variable in HypnosisterAppDelegate.h

#import <UIKit/UIKit.h>
#import "HypnosisView.h"

@interface HypnosisterAppDelegate : UIResponder <Some protocols>
{
    HypnosisView *view;
}
@property (strong, nonatomic) UIWindow *window;
@end

Then in the .m file we access the iVar directly in a few spots. My question is, if we are only using this iVar in the HypnosisterAppDelegate class, why not declare a property for this iVar in the .m file and use the set/get methods to access it like below:

#import "HypnosisterAppDelegate.h"
#import "HypnosisView.h"

@interface HypnosisterAppDelegate()
@property (nonatomic) HypnosisView *view;
@end

@implementation HypnosisterAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // removed code that didn't pertain to my question
    
    // auto @synthesize creates the _view iVar
    _view = [[HypnosisView alloc] initWithFrame:screenRect];
    
    // and then we can use the get method to retrieve the object instance rather than calling the iVar directly
    [scrollView addSubview:[self view]];
    // instead of [scrollView addSubview:_view]
}

@end