Learn the style and structure of iOS (architecture) in simple language
Here we want to learn the style and structure of iOS architecture in swift with examples, as well as different layers in the structure and style of iOS xcode application and application files (xcode iOS (main.storyboard, viewcontroller.xwift, info.plist, appdelegate We learn .swift with examples.
IOS life cycle and structure
Before we start studying the iOS life cycle or architecture, we will create a simple iOS project using Xcode. If you do not know how to create a project in iOS using Xcode, do not worry; We will learn all of these in detail in later chapters. When we create the iOS project, the application interface and file structure will be as shown below.
We now learn the iOS life cycle using the project above. If you see the screenshot of the program above; On the left, we have the different files as shown below; its available.
We now learn that these files are in the iOS life cycle to access the functionality we want; They are efficient.
Main.storybord file
The Main.storyboard file is a visual representation of our application interface, and we use the Main.storyboard file to design our application page.
ViewController.Swift file
This file is used for our implementation section where we write our code, this ViewController.Swift file will look like the following figure.
Info.plist file
This file actually contains the configuration of our program. For example, it includes the original name of the Main.storyboard file and the setup interface file, and more.
AppDelegate.Swift file
Like other programming languages, iOS has a special file that always runs first and is called the AppDelegate.Swift file. When the program runs; First, the compiler goes to the AppDelegate.Swift file and checks the @UIApplicationMain marker. This marker is the most important topic in the program. If we comment on this marker; Our program is built properly but does not run.
The normal lifecycle of the iOS app starts with @UIApplicationMain, when we run the app the object is first created and valued. After creating and initializing the object, AppDelegate.Swift will turn on and the UIApplication object will return to the AppDelegate.Swift file. The @UIApplicationMain file reads the info.plist file and examines your program configuration, including the startup screen name and the Main.Storyboard file. This general process is done in the background.
The AppDelegate.Swift file now goes to the UIWindow, which is an invisible window, and this window automatically; Created as part of the program.
This UIWindow contains a border line that draws the screen of iPad, iPhone, etc.
This means that if we launch an image on the screen, it will first load in our invisible UIWindow when the program is loaded, as shown below.
When our app load is complete; The startup screen then disappears and the UIWindow loads with the first view controller, as follows; Includes our program controls.
For the UIApplication object we do not need to do anything, here the main file is AppDelegate.Swift and it shows the status of our application and the UI window draws the pages of our application.
At the launch point of the iOS app; If we want to do things that when using the lifetime method; Required: application: didFinishLaunching is called and this method is passed through our AppDelegate.Swift file. After completing the application method: didFinishLaunching; then the window is loaded with ViewController (view controller) and in ViewController the method that will be executed first is known as ViewDidLoad () and ViewDidAppear () method and these are the internal methods of ViewController . After this method didBecomeActive is called and our program is ready.
This is the full life or architecture of how an iOS app works.