zoukankan      html  css  js  c++  java
  • 关于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信号
  • 相关阅读:
    pytest实现参数化(@pytest.mark.parametrize)
    pytest标记测试用例为预期失败(@pytest.mark.xfail)
    pytest标记跳过某些测试用例不执行
    pytest的conftest.py配置
    pytest之fixture使用
    模拟赛42 题解
    模拟赛41 题解
    一些可能永远用不到的性质
    补锅
    骗分杂谈
  • 原文地址:https://www.cnblogs.com/ashamp/p/4534223.html
Copyright © 2011-2022 走看看