Reactivecocoa (known as RAC) is a new framework developed by GitHub, an Open-source application for iOS and OS X. RAC has the characteristics of functional programming and responsive programming. It was mainly absorbed. NET, the design and implementation of reactive extensions. This article will describe in detail what the framework is trying to solve, as well as its usage and characteristics.
Reactivecocoa trying to solve any problem
After a period of research, I think Reactivecocoa is trying to solve the following 3 questions:
The problem of excessive dependencies between state and state during the development of the traditional iOS
The problem with the traditional MVC architecture: Controller is more complex and testability is poor
Provides a unified messaging mechanism
The problem of excessive dependencies between state and state during the development of the traditional iOS
When we develop iOS applications, the state of an interface element is likely to be affected by several other interface elements or background states.
For example, in the user account login interface, there will usually be 2 input boxes (enter the account number and password, respectively) and a login button. If we want to add a restriction: When the user enters the account number and password, and the logon network request has not been issued, the OK button can be clicked. Typically, we need to listen for the state of the two input boxes and the status of the network requests that are logged in, and then modify the enabled state of the other control.
The traditional wording is as follows (the sample code is modified from REACTIVECOCOA official website): Https://github.com/ReactiveCocoa/ReactiveCocoa
static void *observationcontext = &ObservationContext;
(void) Viewdidload {[Super viewdidload]; [Loginmanager.sharedmanager addobserver:self forkeypath:@ "Loggingin" Opti
Ons:nskeyvalueobservingoptioninitial context:&observationcontext]; [Self.usernametextfield addtarget:self Action: @selector (Updateloginbutton) Forcontrolevents:uicontroleventedi
Tingchanged]; [Self.passwordtextfield addtarget:self Action: @selector (Updateloginbutton) Forcontrolevents:uicontroleventedit
Ingchanged]; }-(void) Updateloginbutton {BOOL textfieldsnonempty = self.usernameTextField.text.length > 0 && SELF.PA
SswordTextField.text.length > 0; BOOL Readytologin =!
LoginManager.sharedManager.isLoggingIn &&!self.loggedin;
self.logInButton.enabled = Textfieldsnonempty && readytologin;
}-(void) Observevalueforkeypath: (NSString *) KeyPath Ofobject: (ID) object Change: (nsdictionary *) Change context: (void *) Context {if (context = Observationcontext) {
[Self Updateloginbutton]; else {[Super Observevalueforkeypath:keypath ofobject:object Change:change Contex
T:context];
}
}