关于ReactiveCocoa的RACObserve的一些研究

1.RACObserve能够用来观察一个NSMutableDictionary的setValue和remove吗?atom

能够spa

一个对象有一个propertycode

@property(nonatomic,strong)NSMutableDictionary *testDict;

 

使用RACObserve进行观察对象

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

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

    }];

在对dict进行setValue或remove时blog

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

便可.rem

2.能够RACObserve属性(property)的属性(property)吗?io

能够table

假设有个TestObject类class

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

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

@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信号
相关文章
相关标签/搜索