why the type of `nil` is not `id` but `void *`

前端 未结 3 757
终归单人心
终归单人心 2021-01-17 23:49

In this code

id (^block)(void) = ^(void) {
    return nil;
};

I have this error

Incompatible block pointer types ini

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-18 00:42

    You're using an inferred return type for your block literal, but you don't have to.

    The correct way to remove that error is to provide a return type for the block literal:

    id (^block)(void) = ^id{
        return nil;
    };
    

提交回复
热议问题