title: Updating a UITableViewCell from a view model with ReactiveCocoa
body: <p>I am trying to code with <strong>ReactiveCocoa</strong> and the <strong>MVVM</strong> pattern and I am trying to setup a custom <code>UITableViewCel</code>l to update its labels when the according <code>viewModel</code> is getting a new model object.</p>
  
  <p>The unit tests are passing so I know the view model itself is working so far. But I do not get the <code>UILabel</code>s to update their attributed text.</p>
  
  <p>Here is my code for the <code>UITableViewCellModel</code>:</p>
  
  <pre><code>@interface GYMWorkoutTableViewCellModel : NSObject
  @property(nonatomic, copy, readonly) NSAttributedString *workoutName;
  @property(nonatomic, copy, readonly) NSAttributedString *numberOfExercises;
  @property(nonatomic, strong) GYMWorkout *workout;
  @end
  
  @implementation GYMWorkoutTableViewCellModel
  - (id)init {
      self = [super init];
      if (!self) return nil;
  
      RACSignal *newWorkoutSignal = [RACObserve(self, workout) ignore:nil];
  
      RAC(self, workoutName) = [newWorkoutSignal map:^id(GYMWorkout *workout1) {
          return [[NSAttributedString alloc] initWithString:workout1.name];
      }];
  
      RAC(self, numberOfExercises) = [newWorkoutSignal map:^id(GYMWorkout *workout2) {
          NSString *numberOfExercisesString = [@([workout2.exercises count]) stringValue];
          return [[NSAttributedString alloc] initWithString:numberOfExercisesString];
      }];
  
      return self;
  }
  
  @end
  </code></pre>
  
  <p>And here is the code for the cell itself: </p>
  
  <pre><code>@interface GYMWorkoutTableViewCell : UITableViewCell
  @property(nonatomic, strong) IBOutlet UILabel *workoutNameLabel;
  @property(nonatomic, strong) IBOutlet UILabel *numberOfExercisesLabel;
  @property(nonatomic, strong) GYMWorkoutTableViewCellModel *viewModel;
  @end
  
  @implementation GYMWorkoutTableViewCell
  
  - (id)initWithCoder:(NSCoder *)coder {
      self = [super initWithCoder:coder];
      if (!self) return nil;
  
      self.viewModel = [GYMWorkoutTableViewCellModel new];
  
      RAC(self.workoutNameLabel, attributedText) = RACObserve(self, viewModel.workoutName);
      RAC(self.numberOfExercisesLabel, attributedText) = RACObserve(self, viewModel.numberOfExercises);
  
      return self;
  }
  @end
  </code></pre>
  
  <p>I am setting the workout property in the <code>tableView:cellForRowAtIndexPath:</code> method of the according view controller like this: </p>
  
  <pre><code>GYMWorkoutTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"WorkoutCellIdentifier" forIndexPath:indexPath];
  GYMWorkout *workout = [self.viewModel workoutAtIndexPath:indexPath];
  cell.viewModel.workout = workout;
  return cell;
  </code></pre>
  
  <p>Can anyone give me hints why the <code>RAC()</code> bindings in the <code>GymWorkoutTableViewCell</code> do not update the <code>UILabel</code>s?</p>
  
  <h2>Edit</h2>
  
  <p>When I change the code in the <code>initWithCoder:</code> method to </p>
  
  <pre><code>[RACObserve(self, viewModel.workout) subscribeNext:^(GYMWorkout *gymWorkout) {
          self.workoutNameLabel.text = gymWorkout.name;
  }];
  </code></pre>
  
  <p>the text of the <code>UILabel</code>s is changed. But this defeats the need for the model.</p>