当返回值的类型是CGFloat时,如何使用ReactiveCocoa sendKeypath

时间:2015-10-09 08:38:14

标签: ios reactive-cocoa reactive-cocoa-3

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

错误日志是:

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

并且我认为如果有另一种方式来反应值类型是浮点数,int等等.i会接受它

1 个答案:

答案 0 :(得分:3)

您应该使用字符串而不是@keypath宏。

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

或者您可以使用更清晰的RAC宏。

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