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信号
  • 相关阅读:
    Python 集合
    Python sorted()
    CodeForces 508C Anya and Ghosts
    CodeForces 496B Secret Combination
    CodeForces 483B Friends and Presents
    CodeForces 490C Hacking Cypher
    CodeForces 483C Diverse Permutation
    CodeForces 478C Table Decorations
    CodeForces 454C Little Pony and Expected Maximum
    CodeForces 313C Ilya and Matrix
  • 原文地址:https://www.cnblogs.com/ashamp/p/4534223.html
Copyright © 2011-2022 走看看