IOS builds a highly available App framework from 0 to 1

Recently in the iOS framework to build new projects, has been set up in the framework of high availability App how to think, can avoid the reconstruction of late because of the code quality. Before taking over many “rotten code”, the underlying architecture is loose, confusion, lack of standardization, the development team leading code style, the code structure is clear and good project is the key to ensure the quality of products, the share structure of my ideas.

Architecture diagram:

IOS builds a highly available App framework from 0 to 1
architecture diagram

Architectural principles: readability, ease of maintenance, scalability.

I. thinking

One good thing to do is spend more time thinking than doing it.

First of all, according to product requirements and design drawings, the brain first to establish a product architecture:

1. what is the positioning of the product?.

Socialize? Media? Play? Sports? AV? Electricity supplier…… To be clear about what you want to do a type of App, different types of products, technology selection is also different, in which I was to build a basic App architecture, can be the basis for social development, electricity, audio and video etc.!

2. technology selection

According to current product requirements and possible future requirements (how do I know what the future needs? Can refer to competing products, you can play the imagination, if the product said: “we want to do IM text chat, only text.”! Do not do audio and video, do not do later!” A commitment like that, if you believe in him…… The back story is wonderful.. Ha ha ha ha ha ha。。。。 So this time you have to consider to be followed by voice + video chat, don’t be lazy at design time, set aside a certain space, one day when the products go back, you can smile, take time for.

A back to the topic, then said the technology selection, I usually choose some of the current popular, good use of the third party framework, such as YYKit, YYKit is a group of large and powerful iOS components, including Model analysis, image loading, cache and other basic services are designed based on Category, easy to use and the performance is higher than some of the old frame, used to say that good.

The choice of other frameworks can be searched on the GitHub according to the requirements of the project. Each of the stars will be looked at and will give you some ideas.

Program apes can be conservative, ideas must not be too conservative.

Two, build directory structure

IOS builds a highly available App framework from 0 to 1
directory diagram

As above, so I set up App directory structure, from the bottom to the top, use the Pods management framework of third party, the third party framework two package, supply the top use, as far as possible to reduce the coupling between modules, only more clearly.

Three, packaging basic class

IOS builds a highly available App framework from 0 to 1
1. Application Portal

1. AppDelegate is the application of the agent, the application level events are entrusted to it, including boot exit, push and other events, as well as IM, and three party payment callback, which makes the AppDelegate code in the large, is not conducive to perplexing, reading and maintenance, so I added a AppDelegate+AppService class, used to process life cycle business outside of AppDelegate as the event entrance, implementation method of direct call categories, only for the more clear.

IOS builds a highly available App framework from 0 to 1
2. function module

2. Modules contains the function module in the application, according to the bottom of the Tab bar is divided and the associated entity folder (the default is to manually build virtual entity, drag the folder in) use within each module is the MVC model, some people will ask why the Resource and Service folders, MVC is a kind of design idea, death is not routine SA folder, appropriate increase according to the actual demand, in this I choose at the request of the encapsulated data of Service, VC in the call to get the data for the Resource can, why in this, I think that when the module level more, each function module has a number of resources, corresponding to the module is easy to use, also can put the most the outer layer of the Resource folder, the establishment of the corresponding module name, here I choose to public on the outermost Resource, function related to In the Resource folder of the module, just for clarity.

IOS builds a highly available App framework from 0 to 1
3. management module

Definition 3. Manager is global based services, commonly used methods or cases to achieve, mainly includes the application of user management and services, such as network monitoring, advertising page application page; user login login and exit operation state acquisition. Just for clarity.

IOS builds a highly available App framework from 0 to 1
4. utility class

The main folder in the 4. Utils folder is a global generic tool, derived from the two encapsulation of the three party framework, or the tool class written by itself. In this project, I packaged the AES encryption network request tool, the global Toast prompt, the advertisement page and so on. Just for clarity.

IOS builds a highly available App framework from 0 to 1
5. base class

5. Base folder base class used to store project, the base class function contains some customized content, such as page style, empty data page, use the base class to achieve, can be unified control, convenient maintenance and reduce redundancy, also more clearly.

IOS builds a highly available App framework from 0 to 1
6. third party & 7. global macro definition

6., third party folder, put some third party library and third party package, such as third party login, payment, IM, etc., now I have not added third party framework.

The 7. global macro, as its name implies, defines some global common macros. I define four here:

UtilsMacros defines some tool macros, such as access to screen width, system version, data type validation, and so on;

URLMacros defines the server interface address as well as the environment switch;

FontAndColorMacros with the definition of global color, font size, suggested here with the designer to maintain a design specification, such as: the definition of a main tone Acer MainColor, color value is 0x333333, we use MainColor as a global macro background color, when the App revision, color value change, we only need to change the 0x333333, other the code does not need to move, but also to a certain extent constrained designers, do not add a color, the color should be very close to the use of A. If the designer is not willing to maintain this specification, you can try to play a fight, but you can only maintain your own, just for the more clear.

ThirdMacros contains definitions related to third party frames, such as keySecret. Just for clarity.

IOS builds a highly available App framework from 0 to 1
8. resource file

8. resource files, as mentioned above, here I am to store some of the global resources file, the function module I put in the module Resource folder, personal preferences, only for clearer.

IOS builds a highly available App framework from 0 to 1
9. Pods three party management

9., CocoaPods is a dependency management tool for iOS projects. Developing iOS projects inevitably requires the use of third party open source libraries. The presence of CocoaPods allows us to save setup time and third party open source libraries.

That’s what I think about my infrastructure

GitHub source code download, agree with the star

If the same is a coincidence, if there is an error. By: stinky farmer