关于C#:不兼容的块指针类型

Incompatible block pointer types

我收到错误消息:

1
Incompatible block pointer types assigning to 'void (^__strong)(NSString *__strong, NSInteger)' from 'void (^__strong)(NSString *__strong, int)'

对于此代码:

1
2
3
-(void)showInView:(UIView *)view withCompletionHandler:(void (^)(NSString *, int))handler{
_completionHandler = handler;
}

哪里:

1
@property (nonatomic, strong) void(^completionHandler)(NSString *, NSInteger);

看来这应该是一个非常非常简单的修复程序,但我对使它正常工作还不了解。


我认为您正在尝试将其构建为64位目标? NSInteger的定义如下:

1
2
3
4
5
6
7
#if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
typedef long NSInteger;
typedef unsigned long NSUInteger;
#else
typedef int NSInteger;
typedef unsigned int NSUInteger;
#endif

因此,在为64位平台构建时,NSInteger被long类型替换,这会导致此错误,因为您正试图将以int为参数的块分配给期望一个块的属性。 需要很长时间。 您应该使用此:

1
2
3
-(void)showInView:(UIView *)view withCompletionHandler:(void (^)(NSString *, NSInteger))handler{
    _completionHandler = handler;
}