RACSubscriptingAssignmentTrampoline.m 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // RACSubscriptingAssignmentTrampoline.m
  3. // ReactiveCocoa
  4. //
  5. // Created by Josh Abernathy on 9/24/12.
  6. // Copyright (c) 2012 GitHub, Inc. All rights reserved.
  7. //
  8. #import "RACSubscriptingAssignmentTrampoline.h"
  9. #import "RACSignal+Operations.h"
  10. @interface RACSubscriptingAssignmentTrampoline ()
  11. // The object to bind to.
  12. @property (nonatomic, strong, readonly) id target;
  13. // A value to use when `nil` is sent on the bound signal.
  14. @property (nonatomic, strong, readonly) id nilValue;
  15. @end
  16. @implementation RACSubscriptingAssignmentTrampoline
  17. - (id)initWithTarget:(id)target nilValue:(id)nilValue {
  18. // This is often a programmer error, but this prevents crashes if the target
  19. // object has unexpectedly deallocated.
  20. if (target == nil) return nil;
  21. self = [super init];
  22. if (self == nil) return nil;
  23. _target = target;
  24. _nilValue = nilValue;
  25. return self;
  26. }
  27. - (void)setObject:(RACSignal *)signal forKeyedSubscript:(NSString *)keyPath {
  28. [signal setKeyPath:keyPath onObject:self.target nilValue:self.nilValue];
  29. }
  30. @end