1.MVVM Analysis
MVC is the standard Model for building iOS apps, an authoritative paradigm that Apple recommends to organize your code, and most of the apps on the market are built like this, and the specific organizational model is not detailed, and iOS beginners are more aware (though not necessarily fully compliant), But some of its unavoidable problems are very serious to the developers, such as heavy Viewcontrolller, lost network logic (not in its place), poor testability and so on. So there is the prevalence of a new architecture that is very maintainable and very low in coupling, the newest architecture of MVC.
Although MVVM comes from Microsoft, it should not be objected to, it formally regulates the properties of the view and controller tightly coupled, such as:
MVVM diagram
ViewModel: Compared to the new view model introduced by MVC. Is where the view display logic, validation logic, network requests, and so on, the only thing to note is that any reference to the view itself should not be placed in the VM, in other words, is not to introduce UIKit.h in the VM (for image This, some people think of it as data processing, this depends on the individual thinking, does not affect the overall architecture).
In this way, the problem of VC bloated first solved, the logic code, network requests are written to the VM, and then because the VM contains all the presentation logic and does not reference V, so it can be fully tested by programming.
Reactivecocoa is a framework that combines functional programming with responsive programming, or a function-responsive programming (FRP) framework, emphasizing that RAC's greatest advantage is that it provides a single, unified way to handle asynchronous behavior, including the delegate method, Blocks callback, target-action mechanism, notifications and kvo. But don't simply think that he simply reduces the complexity of the code and fits the MVVM better.
Its biggest difference is to provide a new way of writing code thinking, because RAC will cocoa in Kvo, uikitevent,delegate,selector and so on to increase the RAC support, so do not have to do a lot of cross-function things.
If the entire project is implemented using RAC, the same business logic can finally be completed in the same piece of code, the UI events, logic processing, file or database operations, asynchronous network requests, UI results display, this large set of all the ideas of functional programming nested together, into the page to set up all the relationships, The user clicks on the duly waiting for this set of links to be triggered by the desired logic and sequence, and finally displayed to the user.
3. This article on the use of the two understanding
In this presentation, a list of add pull-up and drop-down refreshes is done using the Mvvm+rac combination, so more interpretation of the MVVM idea, rather than the logical chaining of the RAC (which is better represented by the login interface), and the greater part of RAC's role is better decoupled, Reduce the complexity of code, so that the code hierarchy, clear logic to facilitate maintenance upgrades.
Ii. Framework Section
1. Detailed Framework Catalogue
Let's start by introducing the directory structure of this framework, such as:
1, frameworks
To store the virtual folder of the system library, you need to manually add a virtual folder called frameworks when you build the framework, so that the system libraries you add in build phases are automatically categorized into this folder and are not displayed directly outside the directory structure. the system library add process is as follows :
Careful to find that there are two of the same frameworks in this directory, which is why? The top of the frameworks is in his own frame to add, then the project is very simple, the problem is that the following pods target, add it will automatically give you to generate a Asahi Cow Frameworks folder, then asked, why not directly with the following? (There is no conflict between the two)
2, Cocoapods
When developing iOS apps, many third-party open-source libraries, such as jsonkit,afnetworking, are often used. Maybe a class library to use another class library, so to use it, you have to download other class library, and other class library to use other class library, "Descendants endless also", anyway, in the early days of the programmer will experience this pain, sad, manual to download the required class library is very troublesome.
There is another situation where the class library used in the project is updated, and the new version must be re-downloaded and re-added to the project, which is cumbersome.
Cocoapods is to help you solve the problem above, saying that this thing should be the most common iOS most popular class library management tools, as iOS programmers, we have mastered the use of cocoapods is essential to the basic skills.
3, Appdelegate
This directory is a APPDelegate.h (. m) file, which is the entry file for the entire application, so take it out separately. A moment to tell you how to write a concise appdelegate, will add some classes in this folder, so it is necessary to put it in a folder.
4. Class
Engineering Subject class, most of the daily development code is here, but also subdivided a lot of sub-directories.
General class
· General: Generic class (no changes are required during the migration of the folder item, it can be used directly)
。 Base class (base class for the entire framework)
。 Categories: Public extension classes (which are some common categories, such as sharing or something)
。 Core: Public core class (general storage of personal information, interface API, etc.)
。 Models: Public model (some of the common data models)
。 Views: public view (some of the most popular view packages)
Tool class
· Helpers: Engineering related auxiliary classes (such as data requests, form uploads, network monitoring tools, etc.)
Macro Definition Class
· Macro: Macros define the Class (that is, the macro definition used by the entire application)
。 Related macro definitions for AppMacro.h app projects
。 NOTIFICATIONMACRO.H notification-related macro definitions
。 VendorMacro.h third-party related macro definitions
。 UTILSMACRO.H macro definition for simplified code
。 ....... Wait a minute
App specific module code class
· Sections: Folders for each module (in general, we are in human units)
。 Lwsections Lao Wang's folder
。 ...... Wait a minute
Each member of the folder is the folder of its own module, for example, Ms. Cang is responsible for the PHP interface module, as follows
· PHP: module name, can also be the homepage (homepage) ... Wait a minute
。 Viewcontrollers Interface Controller repository (this is the folder name)
。 ViewModels (the core of MVVM, decoupling, processing logic, etc.)
。 View-related view storage (interface-related sub-view)
。 Models Data Model Store (a variety of simple data models, not fat at all, is the standard thin model)
This is the standard MVVM.
Third-party class libraries
· Vendors: third-party class library/sdk, such as Umeng, WEIBOSDK, WEIXINSDK, and so on.
The Cocoapods did manage most of the third-party libraries, and there are two reasons to create a third-party library: First, not all of the third-party libraries you need support pods, so you still need to add some class libraries manually. Second, some third-party libraries support pods, but we need to change or even customize this third party, this time also need to be put here, and also prevent the use of pods accidentally update the custom.
5, Resource
Here are all the resources needed for the project, as follows
· Fonts fonts
· Image Image (Of course you can add to Assets.xcassets)
· Sounds Sound
· Videos Video
2, the base class detailed
Here the focus on the VC, V, VM base class, the other mode and view similar so skip, where the base class Tableviewcell is slightly special so also mention.
The current base class is as follows:
Once I feel the base class is not pleasing to the eye, have tried to kill all the base class, and then encountered some trouble.
[Hmly] 7.iOS Mvvm+rac from frame to combat