10

I am learning ReactiveObjC , the ReactiveCocoa Objective-C version.

For the code following: In RACSignal.h ,

- (RACSignal *)reduceEach:(id _Nullable (^)())reduceBlock RAC_WARN_UNUSED_RESULT;

(id _Nullable (^)())

Xcode reports a error:

This block declaration is not a prototype

Multiple parameters could be put in the reduceBlock(). As the code following: In UIAlertView+RACSignalSupport.m , and others ,

- (RACSignal *)rac_buttonClickedSignal {
    RACSignal *signal = [[[[self.rac_delegateProxy
        signalForSelector:@selector(alertView:clickedButtonAtIndex:)]
        reduceEach:^(UIAlertView *alertView, NSNumber *buttonIndex){
            return buttonIndex;
        }]
    ......
    return signal;
}

Kinda generic. I think I can put zero or more parameters in the block, with void (^block)() declared.

The syntax is not supported now in Xcode. I want to know how to solve it, and why.

Many Thanks in advance.

2 Answers 2

20

You can get the "not a prototype" warning when you try to define a function or block prototype using an empty set of parentheses ().

Put a void in the middle of the parens—i.e. (id _Nullable (^)(void)), and you should fix the problem.

Sign up to request clarification or add additional context in comments.

9 Comments

I think , the answer is that way ` (id _Nullable (^)(id _Nullable ,...))`, It's not that easy . (id _Nullable (^)()), I saw the syntax many times.
@dengApro Did you try it? The default warning settings for Clang in Xcode have gotten stricter about this in recent versions. Putting void in the parens really should fix it.
@dengApro Then just define it as variadic, the way -[NSString stringWithFormat:] does, using an ellipsis. (id _Nullable (^)(NSString *, ...))
@dengApro: To add to CharlesSrstka's comment, if you use block type with a variadic parameter, then the block implementation needs to actually take a variadic. The type must match the block signature. If you try to call a block expression with a block type that doesn't match the actual signature of the block that it points to at runtime, it will cause undefined behavior.
|
0

If you redefine your signature to accept an array instead of an arbitrary number of parameters, then you’ll workaround it easily

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.