简体   繁体   中英

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

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;
    }];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM