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信号
  • 相关阅读:
    练习JSON
    实现JSON+JDBC的简单操作(以显示对象为例)
    三层架构:表示层-业务逻辑层-数据访问层
    实现json的三个操作(训练JSON)
    实现邮箱验证 简化版
    复习注册表单html和jQuery
    监听器(测试在线人数的)第一种 HttpSessionBindingListener
    Django的中间件
    Django form表单
    Django
  • 原文地址:https://www.cnblogs.com/ashamp/p/4534223.html
Copyright © 2011-2022 走看看