title: Using reactive cocoa to concisely fetch local data and then update with remote data
body: <p>I am trying to implement a RACCommand that can be executed to initiate display of the freshest available data to the UI.</p>
  
  <p>Both sendNext: calls would return data from the local database and a remote server respectively.</p>
  
  <p>Is there are more concise way to achieve the same behaviour?</p>
  
  <pre><code>self.testObjects = @[ @"initial" ];
  
  RACCommand *command = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
      RACSignal *s1 = [RACSignal createSignal:^RACDisposable *(id &lt;RACSubscriber&gt; subscriber) {
          [subscriber sendNext:@[@"value1", @"value2"]];
          [subscriber sendCompleted];
          return [RACDisposable disposableWithBlock:^{
              // Cleanup
          }];
      }];
  
      RACSignal *s2 = [RACSignal createSignal:^RACDisposable *(id &lt;RACSubscriber&gt; subscriber) {
          [subscriber sendNext:@[ @"value1-updated", @"value2" ]];
          [subscriber sendCompleted];
          return [RACDisposable disposableWithBlock:^{
              // Cleanup
          }];
      }];
  
      return [RACSignal createSignal:^RACDisposable *(id &lt;RACSubscriber&gt; subscriber) {
          [s1 subscribeNext:^(id x) {
              [subscriber sendNext:x];
          }];
  
          [s1 subscribeCompleted:^{
              [s2 subscribeNext:^(id x) {
                  [subscriber sendNext:x];
              }];
          }];
  
          return [RACDisposable disposableWithBlock:^{
              // Cleanup
          }];
      }];
  }];
  
  RACSignal *racSignal = [command.executionSignals switchToLatest];
  RAC(self, testObjects) = racSignal;
  
  [[self rac_valuesAndChangesForKeyPath:@"testObjects" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial observer:self] subscribeNext:^(RACTuple *x) {
      RACTupleUnpack(NSArray *values ) = x;
      NSLog(@"values: %@", values);
  }];
  
  [command execute:nil];
  </code></pre>
  
  <p>Outputs:</p>
  
  <p>values: (
      initial
  )</p>
  
  <p>values: (
      value1,
      value2
  )</p>
  
  <p>values: (
      "value1-updated",
      value2
  )</p>