iosreactive-cocoareactive-cocoa-3

How to use ReactiveCocoa to sendKeypath when the type of return value is CGFloat


       self.subscription = [[[RACObserve(photoModel, fullsizedData) filter:^BOOL(id value) {
                return value != nil;
          }]map:^id(id value) {
    return [NSNumber numberWithFloat:1.0f];
    } ]setKeyPath:@keypath(self.imageView.layer,borderWidth)onObject:self.imageView];

error log is:

   Terminating app due to uncaught exception 'NSUnknownKeyException',
   reason: '[<UIImageView 0x7b1a8510> setValue:forUndefinedKey:]:
   this class is not key value coding-compliant for the key cornerRadius.

and i think if there is another way to react the value who's type is float,int and so on .i will accept it


Solution

  • You should use string instead of a @keypath macro.

        [... setKeyPath:"layer.borderWidth" onObject:self.imageView];
    

    Or you can use the RAC macro which is much clearer.

        RAC(self.imageView, layer.borderWidth)
        = [[RACObserve(photoModel, fullsizedData) filter:^BOOL(id value) {
            return value != nil;
        }] map:^id(id value) {
            return @1.0f;
        }];