RAC初识--004--RACSubject

RACSubject :信号提供者!!,自己可以充当信号,又能够发送信号!!

#import "ViewController.h"

#import <ReactiveCocoa/ReactiveCocoa.h>


@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    

    //1.创建信号

    RACSubject * subject = [RACSubject subject];

    

    //2.订阅信号

    //不同的信号订阅的方式不一样!!(因为类型不一样,所以调用的方法不一样)

    //RACSubject处理订阅:拿到之前的_subscribers保存订阅者

    [subject subscribeNext:^(id x) {

        NSLog(@"接受到了数据:%@",x);

    }];


    //3.发送数据

    //遍历出所有的订阅者,调用nextBlock

    [subject sendNext:@"汉堡包"];

    

}



- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}



@end






猜你喜欢

转载自blog.csdn.net/qq_33226881/article/details/78210087
004
今日推荐