The model is not something standard, like everything else that you talked about. When creating a single view application in Xcode, it comes with a viewController and appDelegate. As you noticed, the model is missing.
This is because you create your own model. A model is usually an object that you create in your view controller, and then manipulate your data using your methods. The model will be a .h and .m file that you create to create an object that, using its methods, manages data from user input.
Because it is not a good practice for your opinion to speak directly with your model, and vice versa, your viewController acts as a link. The view (buttons, labels) contains data on the screen that viewController can access. As soon as the viewController has access to this data, it sends this data to the model. As mentioned earlier, a model can be an object that you create in your viewController . This is the thinking of your application and manipulates the data that your views manager sends.
A good place to instantiate your model is the viewDidLoad method. This ensures that when your application is ready, your model will also be.
- (void)viewDidLoad { [super viewDidLoad]; self.myModel = [[Model alloc] init]; }
And a reference to your model as an instance variable should be placed in the extension of your private class at the top of your viewController .m file.
@interface ViewController () @property (nonatomic) Model *myModel; @end
source share