REACTIVECOCOA Programming Framework Learning (I.)

Source: Internet
Author: User

Reactivecocoa

Reactivecocoa is a function-responsive programming (FRP) framework.

1. Function-type programming: write the operation as much as possible into a series of nested functions or method calls.

2, responsive programming: Do not need to consider the sequence of calls, just need to know the results, similar to the butterfly effect, the occurrence of an event, will affect a lot of things, these events like the flow of the spread out, and then affect the results.

--------------------------------------------------------------------------------------------------------------- -------------------------------------------------

(i) Reactivecocoa Core class racsignal

Racsignal Steps to use:

//1. Create Signal + (racsignal *) createsignal: (racdisposable * (^) (id<racsubscriber> subscriber)) Didsubscribe

//2. The signal is only activated if the signal is subscribed.-(Racdisposable *) Subscribenext: (void (^) (id x)) nextblock

//3. Send signal-(void) Sendnext: (ID) value

//Racsignal Bottom implementation:

//1. To create a signal, first save the didsubscribe to the signal, it will not be triggered.

//2. When the signal is subscribed, that is to call Signal's Subscribenext:nextblock

The subscriber Subscriber is created inside the//2.2 subscribenext, and Nextblock is saved to subscriber.

//2.1 Subscribenext internally calls SIGANL's Didsubscribe

//3.SIGANL in Didsubscribe [subscriber sendnext:@1];

//3.1 sendnext The bottom is actually the implementation of subscriber Nextblock

--------------------------------------------------------------------------------------------------------------- -------------------------------------------------

code example:

--------------------------------------------------------------------------------------------------------------- -------------------------------------------------

//1. Create a signal

--------------------------------------------------------------------------------------------------------------- -------------------------------------------------

Racsignal *siganl = [racsignal createsignal:^racdisposable * (ID<RACSubscriber> subscriber) {

//Block call time: block is called whenever a subscriber subscribes to a signal.

--------------------------------------------------------------------------------------------------------------- -------------------------------------------------

//2. Send Signal

--------------------------------------------------------------------------------------------------------------- -------------------------------------------------

[Subscriber sendnext:@1];

//If the data is not sent, it is best to send the signal to complete, the internal will automatically call [racdisposable disposable] unsubscribe signal.

[Subscriber sendcompleted];

return [racdisposable disposablewithblock:^{

//Block call time: When the signal is sent or the error is sent, the block is automatically executed and the subscription signal is canceled.

//after the block is executed, the current signal is not subscribed.

NSLog(@ "signal is destroyed");

}];

}];

--------------------------------------------------------------------------------------------------------------- -------------------------------------------------

//3. The signal is not activated until the signal is subscribed.

--------------------------------------------------------------------------------------------------------------- -------------------------------------------------

[Siganl subscribenext:^ (ID x) {

//Block call time: block is called whenever a signal is emitted.

NSLog(@ "received data:%@", x);

}];

REACTIVECOCOA Programming Framework Learning (I.)

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.