簡體   English   中英

當返回值的類型為CGFloat時,如何使用ReactiveCocoa發送sendpath

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

錯誤日志是:

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

我認為如果還有另一種方法可以反應類型為float,int等的值,.i會接受

您應該使用字符串而不是@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;
    }];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM