On iOS code layout < a >

Source: Internet
Author: User

When we need to develop an iOS app, we usually take into account the application's development framework first. iOS development differs based on pure code layout and Xib,storyboard layout, where only pure code layout is discussed. Because the layout of pure code is more efficient in code migration, reuse is more convenient.
Typically an iOS app is divided into logic layers (classes that handle logic), the UI layer (the class that handles the interface), the network layer (processing network interfaces), the base layer (some third-party controls, or a tool class that you write yourself), the attribute base class (the global generic attribute class or the specific attribute class used at the logic level). The code of the base layer and the network layer can be migrated in each project, so we can encapsulate them and make them into a static library or a dynamic library for easy migration.
What are the main elements of the logic layer, where I define logic as the control layer in MVC, the controller, when we need to create an interface, we usually start by creating a category, the Uiviewcontroller class, (Of course I know a lot of people like to think of Uiviewcontroller as a collection of interfaces, a Controllor interface, logic and interface implementations are all done here). But here, I do not advocate this, thinking that this is not conducive to the logic layer and the UI layer to cut out. So, what are we going to do here, I'm going to provide a way of thinking that when we create the Uiviewcontroller, we also create a uiview, and we give the controller inside the Self.view to the newly created UIView processing. In other words, we can manipulate the interface by means of the method, rather than solving it internally. So, what we have to do in the logic layer is to handle notifications and callbacks, submit network requests, State and permission handling, and so on. In the processing of the large interface, the code here may be very large, and of course, the basic layer is needed to share a large part of the complex functions. That is, the logic layer, will be the UI, the network, the base layer of the collection center, he accepted the information they gave, and then processed distributed, this is the logic layer of the specific functions.
What is the UI layer, in fact, a complete interface, the UI layer needs to do a lot of things (his things are not less than the logic layer), so we need to separate the UI and logic completely. First, the UI layer may be dealing with far more than you initially imagined, matching iphone4,iphone5,iphone6 (currently the same size as the iphone5 and Iphone6, but the @2x,@3x of the picture, of course, the tool can automatically recognize), the ipad , it is possible to match the horizontal screen, vertical screen. Matching UI processing alone is enough to complicate a simple interface. If it's a complex UI interface, you might also be able to manipulate animations, graphics and text (and, of course, help from the base layer). Of course, the basic function of the UI is to get commands from the logic layer to change the state of the interface.
The network layer, this is the simplest level, the thing he wants to do is very simple, is the interface link and debugging. Usually a common network base class and an interface classification. In general, it is reasonable to place 50 or so interfaces in an interface category. Network base class For example, ASIHTTPRequest, he mainly dispose of some data transmission format and return status is sufficient. As for classification, it handles the parameters of the interface, the transmission mode (post or get), (the return parameter is not recommended here, because it is usually called directly in the logic layer, so it is processed in the logic layer). Of course, there may be some video, the data type of transmission, will involve the extension of the breakpoint, and so on, which will be done by a special tool class, which is only used in the background and simple data transmission.
The basic class, or the tool layer, handles a complex but more general function here. For example, animation operations, graphics and text, input bar chat tools, custom albums and a variety of custom controls. There are a variety of commonly used functions (so, generally divided into more complex base class and relatively simple Unite class). The general base class needs to be completed with multiple files, while simple unite only need one.
Attribute class, his function is also very simple, global such as user class, or just for some common scenarios need a few logic layer to common transfer and use of special class attributes, mainly to facilitate the specification of the type of data in the transfer, you can also standardize a logic to use the data type, This can be defined as the model in MVC.
Here the layout of the structure of the introduction, the time to update the picture.

On iOS code layout < a >

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.