ReactiveCocoa。返回类型'UIImage *'必须与之前的返回类型'void *'匹配

时间:2014-02-02 16:36:40

标签: objective-c ios7 reactive-cocoa

@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (nonatomic) UIImage *image;
@property (nonatomic) PhotoEffect *effect;
@property (weak, nonatomic) IBOutlet UISwitch *glossSwitch;

我正在尝试使用已修改的图片更新imageViewUISwitch更改其值,或_image_effect已更改。

RAC(self.imageView, image) = [RACSignal
                                  combineLatest:@[ RACObserve(self, image), RACObserve(self.glossSwitch, on), RACObserve(self, effect)]
                                  reduce:^(UIImage *im, NSNumber *gloss, PhotoEffect *effect) {
                                      if (!im) {
                                          return nil;
                                      }
                                      if (effect) {
                                          im = [im imageWithEffect:effect.type];
                                      }
                                      if (gloss.boolValue) {
                                          im = [GlossyIcon applyShineToImage:im];
                                      }
                                      return im;
                                  }];

这段代码给出了编译错误,我无法理解:

Return type 'UIImage *' must match previous return type 'void *' 
when block literal has unspecified explicit return type

1 个答案:

答案 0 :(得分:3)

由于reduce块可以返回nilUIImage *,因此编译器无法推断块的返回类型。明确声明reduce块的返回类型可以解决问题,您可以使用id来简化,或UIImage *清除。

    reduce:^UIImage * (UIImage *im, …) {