IOS project-build a project development environment and build an ios Project
Before developing a project, we need to make some preparations to understandIOS extension-Objective-C development programming specificationsIs an essential foundation for development and learning.IOS learning-upload a project to GitHub in Xcode9Is one of our choices for version control and code management.IOS learning-how to configure the iOS Project and TargetsThis is more conducive to the establishment of the complete project development environment today. These content has been summarized and described in the previous blog. For details, click the link to view them.
Developing a complete App is different from creating a project at will when we study and practice, and then writing our sample code is complete. You need to develop a complete App. There are certain development procedures. In general, many people work together in the development process. Each person is responsible for the development of some functional modules, and finally merging, debugging, testing, and launching processes. At the beginning of project development, we need to build our App development environment. At the beginning of an App development, the environment establishment mainly includes the following parts.
1. modify the application name displayed after the App is installed.
When we first create a project, the App name is the same as our project name by default. Generally, the name of our project does not need to be in Chinese, basically, the App name and our project name are different. Therefore, at the beginning of the project, the App name needs to be modified. Currently, you can directly modify the display name of the App in three locations, one of which is the modifier, and the other two are automatically modified, as shown in.
2. Set the class name prefix.
In the project development process, we generally need to add a prefix to all classes in the project to distinguish whether we create the class by ourselves or a third party or the class that comes with the system. This prefix is custom, generally, it is set to the abbreviation or first letter of the company name. For personal development, you can set it as needed. The setting interface is shown in.
In addition to setting the class name prefix, two additional settings are also marked:
- One is the text setting option in the lower right corner.IOS extension-Objective-C development programming specificationsAs mentioned in, we recommend that you use spaces for indentation and segmentation in iOS development, rather than tab indentation. Here we set the meaning represented by the tab key and indent four spaces. Indent indicates that the number of indentations in the next line is also 4 spaces.
- The other is the Organization setting, which indicates the copyright of the Software. Each class in our project has a class description comment, as shown in, the organization settings here indicate the Copyright of the Copyright program. Generally, the name of the company can be set to Chinese or custom. The default name is the name of your computer.
3. Adjust the App direction
In general, the direction of our application software is vertical screen positive (except for games, General games are landscape ), therefore, before developing a project, we can determine the device type and screen direction. This allows us to cut and set the application icon and startup image, shows the screen direction setting interface.
Some of the content in this section is as follows:IOS learning-how to configure the iOS Project and TargetsAs mentioned in, the deployment attribute of target is set to set the status of the App installed on the mobile phone. We can see that:
- The device direction is available in four directions. Generally, you can select a portrait screen, except for apps with special features.
- We can also set whether our device type is iPhone or iPad or both.
- The style of the status bar, which can be selected based on your needs. Of course, whether to hide the status bar, we can also set it through code as needed during the development process.
- You can set whether to hide the status bar and whether to enable full screen settings as needed.
For example, when developing a game similar to the glory of the King, the options here should be the device type select Universal, the device direction is the left horizontal screen + Right horizontal screen, check to hide the status bar, colleagues also select the desired full screen.
4. Set the app icon and startup Image
How to set the y8ingyong icon and start ImageIOS learning-how to configure the iOS Project and Targets. As shown in the setting interface, this section mainly sets the application icon and the startup interface. The startup interface can be set to start by setting the startup image or by setting the startup interface file, the START icon and the start interface have different sizes for devices of different models. For details about the size and size of the application icons and the start page, refer to the official website:Human Interface Guidelines.
App icon Source: corresponds to the icon in AppIcon in the file resource Assets. xcassets directory, as shown in. On the rightmost panel, you can select which devices or devices you want to add. the icons of each model have different sizes. For more information about the icons, seeHuman Interface Guidelines. There are small grids in the middle. we drag all the cut icons and they will automatically find the grids they should put in. These small grids are mainly divided into four types:
- Notification: the icon used for Notification. For example, if an application-related push message is displayed, the icon of this application is displayed.
- Spotlight: small search icon. When you enter the app name in Spotlight, the app icon displayed in the search result is of this size, and the icon in the settings is of this size.
- App: this is the normal App icon. The App displayed on the desktop after installation, or the App displayed during recommendation sharing, is also the icon of this size.
- App store: the icon displayed in the App store
Both Luanch Image Source and Luanch Screen File are used to set our startup interface. First, you may wonder why some startup images, advertisements, or motion graphs appear during each App startup, Which is annoying, right? HoweverStarting an image is required.There are two reasons.
- The startup image sets the page on which our App displays the information during this startup. If you do not set the startup interface, after opening our App, a black screen will be displayed, causing the App to become unavailable. If the startup image is an iPhone 6 screen size image, only the screen size area of iPhone 6 is displayed on iPhone X, with two black edges on and off. Therefore, when setting the startup interface, we usually need to adapt to the startup images of various screen sizes. As shown in the following figure, you can see that the Luanch Image Source has multiple sizes.
- Second, when we click the application icon to start the application, it takes some operation time to start the application. During the start period, in order to enhance the user experience when the application is started, you should provide a boot image. The startup image looks very similar to the app's first screen. When a user clicks your application icon on the home screen, the iPhone OS immediately displays the startup image. Once you are ready, your application will display its first screen to replace this startup placeholder image. It must be emphasized that the purpose of providing boot images is to improve the user experience, not to provide: Application entry Experience ", such as starting an animation.
As we have just said, Luanch Image Source and Luanch Screen File are both used to set our startup interface. What are the differences between them?
- Luanch Image Source: corresponds to the file resource Assets. the pictures in the LuanchImage in the xcassets directory set the startup pictures in various circumstances. The specific interface is shown in. Like Appicon, we drag all the cut icons directly, they will automatically find the grid they should put in, and can also select the device and the startup diagram in different directions.
- Luanch Screen File: uses a LuanchScreen. storyboard File as the startup interface.
The main difference between the two methods is thatThe priority of the Startup File is higher than that of the startup image.That is to say, if both are set, the startup page is subject to the Startup File. If neither is set, the application will be black.
In general project development, we generally only use the startup image setting startup interface (because there are many storyboard applications, there are also many ways to set the startup interface by setting the Startup File. You can set it according to your needs and habits.) because the priority of the Startup File is higher than that of the startup image, therefore, we need to delete the file name after the Startup file, and we also need to delete the LuanchScreen in the project. the storyboard file is also deleted because the system automatically searches for LuanchScreen when the App starts. the storyboard file is loaded, so we need to perform these two steps, as shown in.
5. Set the main interface (discard storyboard)
When you create a project, xcode sets the main interface of the App through main. storyboard by default. In addition to setting the main interface, you can also set the interface through code. So how does the system determine how we set the main interface? This issue involves part of the startup process.
As we all know, the main function is the starting point for running the project, which is no exception in our iOS project. We can see that the project has a main. m main function, there is only one method here is our main method, the Code is as follows, very simple.
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
The main function mainly serves the following four points. The last point tells us how to choose the main interface we set.
- Create Application Object
- Create an AppDelegate object and set it to the proxy attribute of the Application object.
- Enable the main loop to keep the program running
- Load info. plist file to determine info. is there main in the plist file. storyboard. If yes, load main. storyboard. If no main. the storyboard determines whether the main interface is created in the project. If the controller is not created, the program cannot be started.
In the actual project development process, we generally use pure code to build the framework, and do not use storyboard to build our App, because the project involves a lot of interfaces and jumps between each other, the storyboard control logic is very confusing, and we usually develop a project with multiple people, with storyboard, you cannot perform multi-person collaboration. Therefore, you need to manually set the main interface in two steps:
6. Build a directory structure
For a complex project, we certainly cannot put all the files directly under a folder directory during the development process. We need to build a directory structure for hierarchical and structured management, in this way, we can quickly locate a functional module when a problem occurs. There is no uniform specification for the directory structure of the project, mainly to facilitate the division of our project modules.
The following two Directory creation methods are recommended:
- The first is to completely separate the model and viewController. For details, refer:IOS Development Summary-project directory structureThe framework is as follows:
Project directory
├── ThirdLib (三方 库)
│ ├── SDWebImage
│ └── AFNetworking
├── Framework (self-encapsulated class library)
├── General
│ ├── Class (generic class, such as a custom parent class)
│ └── Helper
├── Main (single entry of the program, only AppDelegate is used to distinguish other files)
│ ├── AppDelegate.h
│ └── AppDelegate.m
├── Model (Data Model Class Directory)
│ ├── Macro
│ ├── BLL (Business logic layer directory)
│ ├── DAL (Data Access Layer Directory)
│ ├── Entity (custom entity directory)
│ ├── Request (Network Request Catalog)
│ ├── Location
│ └── Socket (Socket class directory)
├── Module
│ │
│ ├─── ModuleA
│ │ ├── ViewControllerA.h (view controller header file)
│ │ └── ViewControllerA.m (view controller m file)
│ ├── ModuleB
│ ├── ModuleC
│ ├── ModuleD
│ └── ModuleE
└── View (view class directory)
└── MyTestView
- The second is differentiated by functional modules. For more information, seeIOSAPP Development Project ConstructionFor example, I personally recommend this type. In Modules, each function module can be divided into model, resource, view, and controller. Such a distinction is more complete, common models or views can be placed in the base.