Ios-rac start with the novice

Source: Internet
Author: User

What is RAC?

In fact, RAC is a simplified code of the third-party library Reactivecocoa, directly with Cocoapods added to the project can be, podfile file add pod ' Reactivecocoa ', and then terminal pod Install, header file reference:

#import <ReactiveCocoa/ReactiveCocoa.h>
Using RAC

1. Methods

The simplest use of RAC is to listen to events.

If you now have a button, if you want to add a click event method to the button, we will typically do this:

/// Add a Click event [Self.button addtarget:self Action: @selector (ButtonClick:) forcontrolevents:uicontroleventtouchupinside]; /// method Implementation -(void) ButtonClick: (UIButton *) sender{    NSLog (@ " click button " );}

But if you use RAC, you can do this:

[[Self.button Rac_signalforcontrolevents:uicontroleventtouchupinside] subscribenext:^ (ID  x) {     NSLog (@ " click button");    }];

Related reference: http://www.jianshu.com/p/ff79a5ae0353

Ios-rac start with the novice

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.