关于ReactiveCocoa的RACObserve的一些研究

1.RACObserve可以用来观察一个NSMutableDictionary的setValue和remove吗?

可以

一个对象有一个property

@property(nonatomic,strong)NSMutableDictionary *testDict;

使用RACObserve进行观察

    [RACObserve(self, testDict) subscribeNext:^(id x) {

        NSLog(@"RACObserve testDict:%@ %p",x,x);

    }];

在对dict进行setValue或remove时

    [self.testDict setObject:value forKey:key];
    self.testDict=self.testDict;

即可.

2.可以RACObserve属性(property)的属性(property)吗?

可以

假设有个TestObject类

@interface TestObject : NSObject
@property(nonatomic,strong)NSString *aProperty;
@end

一个对象有一个该类对象的属性

@property(nonatomic,strong)TestObject *testObj;

可以这样使用

[RACObserve(self, testObj.aProperty) subscribeNext:^(id x) {
        NSLog(@"RACObserve testObj.aProperty %@",x);
    }];
情况如下:
  1.testObj变化时,总会发送信号
  2.testObj为nil时,为aProperty赋值无效,因此不会发送信号
  3.testObj不为nil时,aProperty变化时,会发送信号

2015-09-14 17:27:17追加
RACSignal *repeatSignal = [[RACSignal interval:1 onScheduler:[RACScheduler mainThreadScheduler]] takeWhileBlock:^BOOL(id x) {
            return shouldRepeat;
        }];

  

当shouldRepeat为NO时,将发送completed信号
原文地址:https://www.cnblogs.com/ashamp/p/4534223.html