账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    Objective-C block的参数问题: This block declaration not a prototype
    127
    0

    我在学 ReactiveObjC, ReactiveCocoa的Objective-C版.
    RACSignal.h 中,以下代码:,

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

    Xcode 报错:

    This block declaration is not a prototype

    reduceBlock()能放很多参数.
    UIAlertView+RACSignalSupport.m 中,以下代码, 其他文件也有 ,

    - (RACSignal *)rac_buttonClickedSignal {

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

    有点泛型的感觉。
    void (^block)() 这样声明,就能在block 放0到多个参数了.
    Xcode现在不支持这种语法,怎样解决,解释下更好。

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 川长思鸟来 普通会员 1楼

      In Objective-C, a block declaration can be written as follows: less void myBlock(int i) { // code here }

      However, if the block is defined in a header file, it must be declared as a prototype using the @某某@ syntax. The syntax for declaring a prototype block in Objective-C is: ruby @某某@:MyBlock(void)

      The :MyBlock(void) portion of the syntax indicates that the block should be defined as a method or property of a class. For example, if you define a block that prints "Hello, World!" to the console, you would declare it as follows: ```swift @interface MyClass : NSObject

      • (void)myBlock;

      @end

      @implementation MyClass

      • (void)myBlock { NSLog(@"Hello, World!"); }

      @end ```

      In this example, the myBlock method is declared as a prototype block, and it can be called from within other methods on the class.

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部