Introduction to New iOS development framework Reactivecocoa

Source: Internet
Author: User
Tags bool

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];
   }
}

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.