Iosapp Development Project Construction

Source: Internet
Author: User

Architecture diagram:

Architectural principles: Easy to read, easy to maintain, easy to expand. First, thinking

Do one thing and spend more time thinking than doing it.

First of all, according to the product requirements and design diagram, first build a product architecture:

1. What is the positioning of the product?

Social? Media? Game? Movement? Audio and video? E-commerce ... To find out what kind of app you want to do, different types of products, technology selection is also different, in this I am building a basic app architecture, on this basis to expand Social, e-commerce, audio and video, and so on!

2. Technology selection

Based on current product requirements and possible future requirements (how do I know what needs to be in the future?) can refer to the competition, can play the imagination, if the product said: "We want to do im text chat, only to do text!" Do not do audio and video, do not do in the future! "Like such a promise, if you believe in his evil ... The story behind it is wonderful. haha haha haha .... So this time you have to consider that there will be a voice + video chat, in the design of the time do not lazy, set aside a certain space, when a day product back to the time, you can smile, calmly deal with.

A pull back to the topic, then the technology selection, usually I will choose some of the more popular and useful third-party framework, for example: Yykit, Yykit is a group of large, feature-rich iOS components, including model parsing, image loading, caching and other basic services, are based on category design, Easy to use and performance is higher than some old frame, used well.

Other framework options can be based on the project needs, go to GitHub search, the stars are more than a look at each, will give you a little more ideas.

The program ape is long enough to be conservative, and thought must not be too conservative.

Ii. Building the directory structure
Catalog plots

For example, I build the app directory structure, from bottom to top, using pods to manage the third-party framework, the third-party framework is packaged two times to provide top-level use, minimizing the coupling between the modules.

Three, Package basic class
1. Application Portal

1. Appdelegate is an application agent, application-level events are entrusted to it, including start-out, push and other events, as well as IM, payment and other third-party callbacks, which makes the code in the appdelegate is huge, complex, very bad for reading and maintenance, So I added a Appdelegate+appservice class to handle the business beyond the life cycle, appdelegate as an event entry, to implement the methods in the direct invocation category.


2. Function module

2. Modules contains the application of the function module, according to the bottom tab bar and associated entity folder (the default is virtual to manually set up the Entity folder dragged in), each module using the MVC mode, someone will ask why the Resource and service folder, MVC is a design idea, not a dead routine on the three folders, according to the actual needs of the appropriate increase, in this I choose in the service Package data request, VC call to take data can, as for resource why in this, I think when the function module hierarchy, each large function module corresponds to many resources, Corresponding to the module is convenient to use, of course, can also be placed in the outermost resource folder, to establish the corresponding module name, here I choose to put the public into the outermost resource, function-related to the module in the Resource folder.


3. Management Module

3. Manager is defined as a global basic service, usually using a class method or a singleton to implement, mainly includes the application, the user's management and services, such as network status monitoring, Advertising page Application Introduction page, user quick Login exit operation and login status of access, etc.


4. Tool class

4. The Utils folder contains the global generic tools, which are derived from the two packages of the three-party framework, or the tool classes that they write. In this project, I encapsulated the request tool with AES encryption network, global Toast prompt, ad page, etc.


5. Base class

5. The base folder is used to store the project's basic class, the base class function contains some customized content, such as page style, empty data page, and so on, using the base class to achieve, can unify control, facilitate maintenance, reduce redundancy, also for clearer.


6. Third party & 7. Global macro Definition

6. Third-party folders put some third-party class libraries and third-party encapsulation, such as third-party login, payment, IM, etc. now I have not added a third-party framework to the project.

7. The global macro, by definition, defines some global generic macros. I have defined here four:

Utilsmacros defines some tool macros, such as obtaining screen width, system version, data type verification, etc.

Urlmacros define server Interface address and environment switch;

Fontandcolormacros defines the global use of color values, font size, it is recommended to work with the designer to maintain a design specification, for example: Define a main tone macro maincolor, the color value is 0x333333, we use the Maincolor macro as the background color globally, When one day the app revision, color value changes, we just need to change 0x333333, the other code does not need to move, but also to a certain extent constraints designers, do not arbitrarily add a color, very close to the color should use one. If the designer is unwilling to maintain this specification, you can try a fight, but if you can't beat it, you'll have to maintain it yourself.

Thirdmacros contains definitions related to third-party frameworks, such as Keysecret.


8. Resource Files

8. Resource files, as mentioned above, here I was stored in the global some of the resource files, the function module I put in the module within the Resource folder, personal preferences.


9. Pods three-party management

9. Cocoapods is a dependency management tool for iOS projects, the development of IOS projects inevitably uses a third-party open Source Library, and the advent of cocoapods allows us to save time for setting up and third-party open source libraries.

Architecture diagram

Thinking:

    • First, the face of a version of frequent iterations, the revision of the high frequency of the project, how to design to avoid the more chaotic code?

    • Second, when the business is extremely complex, if the pressure to reduce the VC, so that the code clearer?

    • Iii. How to choose the third-party framework correctly? What are the factors that need to be considered?

Body:

Confront the problem and solve the problem:

First, many entrepreneurial projects in order to rush time on-line, there is no framework design, no code norms, everyone free to play, in a few months will appear poor product experience, crash rate soared, slow development and other problems, have to be reconstructed. In the strategic perspective may be right, the first to occupy the pit again perfect, but in the framework of this is not advisable, or to strictly follow the "high cohesion, low coupling" concept, to ensure that the framework from the bottom service to the top layer of business, each module division of labor Clear, separate, relatively independent, the module through the interface calls, strictly prohibited in a b in the direct use of C, this will make each module entangled devotion, later only will be more and more chaotic.

Many times, now the problem is the original lazy buried the Bane, qualified programmers are basically lazy people, but fell more always have a long memory. Properly overcome the inertia, the pre-frame set up, the real object-oriented programming.

Second, I have taken over a live streaming app, Viewcontroller code on 5500 lines, which is mixed with interface request, data conversion, view management, business logic and so on, read very laborious, bug localization is more difficult, want to reconstruct but not to do, The occurrence of this situation first is not strictly adhere to the modular design concept, the modules do not have their own duties, followed by too strict adherence to the MVC design model, only created the Model View controller three folders, VC pressure is naturally very large.

As I understand it, MVC simply expresses a modular mindset and does not require strict adherence to the MVC directory format.

For example, I took each module on the basis of MVC and pulled out two layers, namely logic layer and service layer. Logic folder, stored in each VC's logical processing class.

Our goal is to liberate the Vc,viewcontroller. As the name implies is the view controller, should not do too much work related to this VC, logic processing to the logic class corresponding to it, logical processing and service calls to get the data and parse, By delegate callback to VC,VC to get the processed data, to render the view.

In doing so, VC only has the interaction with logic, and the management of the view code, it must be clearly a lot.

Module structure

Most applications use some third-party frameworks for rapid development, but there are so many third-party frameworks, how do we choose to be able to maximize their benefits?

First of all to analyze their own applications, all need to use which framework, in the same type of framework to choose the purpose is-in line with their own and timely maintenance, more than a year is not updated to be cautious, the following is my choice of some thinking:

1. Network Framework

Network request is an app must, people usually choose Afnetworking as the basic network framework, but this is only a basic framework, although you can call the request data directly, but if there are some other requirements, such as encryption or public parameters, such as the need to meet the more laborious, So most developers will encapsulate it two times in order to customize some of the requirements, to take control of the request and return data, and to reduce the amount of code churn in the future if the network framework is replaced. Many people themselves encapsulate some simple post get request methods, which are sufficient for small and medium-sized applications to use.

My first choice in the current framework is ppnetworkhelper, because it is relatively easy to use and includes a caching mechanism. Later saw the ape Bank of the network library Ytknetwork, introduced the use of a bit, found that the use of methods and Ppnetworkhelper completely different, ytknetwork the idea is to abstract each interface as an object, instantiate the interface object to initiate a network request, This can be customized for each request, there are some other features, flexibility is strong, suitable for a slightly more complex projects, the framework of the two I have retained, you can choose according to the actual situation of the project, but the recommendations are understood, especially the latter.

Ytknetwork Implementing data requests

2. Base Component Library

Previously mentioned, powerful, excellent performance of the--yykit

It contains components such as parsing data, caching, image processing, text processing, asynchronous drawing, and of course some flaws.

    • yymodel-High-performance IOS JSON model framework.

    • yycache-High-performance IOS cache framework.

    • Yyimage-features a powerful IOS image frame.

    • yywebimage-High-performance IOS asynchronous image loading framework.

    • Yytext-features a powerful IOS Rich text framework.

    • Yykeyboardmanager-ios Keyboard Monitoring management tool.

    • Yydispatchqueuepool-ios Global concurrency Queue management tool.

    • Yyasynclayer-ios the tool for drawing and displaying asynchronously.

    • yycategories-feature-rich category type tool Library

The reason to choose this framework is that the function and performance are relatively strong, with a framework can do a lot of things, and yykit design ideas are category, almost no intrusion, use is very convenient.

But colleagues found yywebimage-this high-performance asynchronous image loading framework might be a bit outdated because it uses nsurlconnection requests, and Sdwebimage has been replaced with urlsession. So the image is loaded asynchronously, I still choose a more professional sdwebimage.

Yykit

3. Layout framework

The biggest difference here is not the framework, but the layout, I understand the developers usually have three layout methods, namely: Code calculation frame, masonry code constraints, sb/xib drag constraints.

I think three ways each have advantages and disadvantages, do not evaluate, lest be scolded, I personally is flexible use, do not despise any one, in different scenes, use the most suitable way, to achieve the best effect, a chestnut: "About Us", a simple display of the page, this time through Xib dragged out this page, It should not be more than 5 minutes, the handwritten code calculation frame may be 10 minutes, and! The code is not intuitive enough to write, other colleagues can not directly see what your page looks like. So either way is not absolutely bad, there is no absolute good, look at the scene, choose Posture.

4. Pull the refresh frame up and down

Most applications will have TableView or CollectionView, pull-up refresh is more commonly used, Mjrefresh provides more powerful features, support customization, provide style complete, update timely, so I choose it!

Mjrefresh

5. Toast Tips

More mainstream two toast hint framework to choose, respectively is Mbprogresshud and Svprogresshud, both updates are more timely, the function is similar, according to personal habits, choose which is not important, it is important to its two times package, let it become better use, In the framework I encapsulated a mbprogresshud+xy category, called by the form of a class method.

Mbprogresshud

The choice of other frameworks, in fact, the same truth, first of all to understand their strengths and weaknesses, in line with their own and timely maintenance of the purpose of choosing is not wrong.

The above content of the source are organized in the Github-universalproject framework, you can download see, by the way small finger point?

Original address: Http://www.jianshu.com/p/f09a4f21e0f9

The following may help you:

    • IOS Team Coding Specification-code specification for team development that needs to be adhered to together

    • Code comments, teach you to use shortcut keys + code block to implement quick comments--so that the comment is no longer a burden, shortcut keys to help you solve

    • Generic tool class macro definition--further improve coding efficiency

Stinky Farm
Links: http://www.jianshu.com/p/d553096914ff

Iosapp Development Project Construction

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.