简体   繁体   English

从不兼容类型'int(^ __ strong)(void)'分配给'int'

[英]Assigning to 'int' from incompatible type 'int (^__strong)(void)'

I am trying to call a block that returns me a random finalItemID (int) according to state of the app. 我正在尝试调用一个块,该块根据应用程序的状态返回一个随机的finalItemID (int)。 But the app fails to build because of the error: 但由于出现错误,该应用无法构建:

Assigning to 'int' from incompatible type 'int (^__strong)(void)' 从不兼容类型'int(^ __ strong)(void)'分配给'int'

My code: 我的代码:

//block declaration
int(^getMeAnItem)(void)=^int(void)
{
int finalItemID=0;
//some randomization code
return finalItemID;
};

int itemIDToBeChecked=0;
itemIDToBeChecked= getMeAnItem; //red error appears on this line

I am not seeing anything wrong going here. 我没有发现任何错误。 I hope you guys can help. 希望你们能帮上忙。 Thanks. 谢谢。

要调用一个块,您需要实际调用它:

itemIDToBeChecked = getMeAnItem();

You initialise a variable named getMeAnItem. 您初始化一个名为getMeAnItem的变量。 An initialisation always ends in a semicolon. 初始化总是以分号结尾。 Yours doesn't. 你的不是。

括号呢?

itemIDToBeChecked = getMeAnItem();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从不兼容类型&#39;void(^)(void)&#39;分配给&#39;NSBlockOperation * __ strong&#39;getNewMessages = ^ {^ ~~ - assigning to 'NSBlockOperation *__strong' from incompatible type 'void (^)(void)' getNewMessages = ^{ ^ ~~ 不兼容的整数到指针转换从&#39;int&#39;分配给&#39;int *&#39; - Incompatible integer to pointer conversion assigning to 'int *' from 'int' 从不兼容类型'ViewController * const_strong'分配给'id <Delegate>' - Assigning to 'id<Delegate>' from incompatible type 'ViewController *const_strong' 分配给&#39;id <UITextFieldDelegate> _Nullable&#39;来自不兼容类型&#39;HomeDataForm * const __strong&#39; - Assigning to 'id<UITextFieldDelegate> _Nullable' from incompatible type 'HomeDataForm *const __strong' 分配给&#39;NSObject <PushNotificationDelegate> *&#39;来自不兼容的类型&#39;AppDelegate * const __strong&#39; - Assigning to 'NSObject<PushNotificationDelegate> *' from incompatible type 'AppDelegate *const __strong' 分配给&#39;id <UIWebViewDelegate> _Nullable”来自不兼容类型“ WebView * const __strong” - Assigning to 'id<UIWebViewDelegate> _Nullable' from incompatible type 'WebView *const __strong' 使用不兼容类型void的表达式初始化NSArray * _strong - Initializing NSArray *_strong with an expression of incompatible type void 整数转换的不兼容指针,从“ id”分配给“ int” - Incompatible pointer to integer conversion assigning to 'int' from 'id' 不兼容的整数到指针转换从&#39;int&#39;分配给&#39;CGFloat *&#39;(又名&#39;float *&#39;) - Incompatible integer to pointer conversion assigning to 'CGFloat *' (aka 'float *') from 'int' 分配给&#39;id <UINavigationControllerDelegate,UIImagePickerControllerDelegate> &#39;来自不兼容的类型&#39;ViewController * const__strong&#39; - Assigning to 'id<UINavigationControllerDelegate,UIImagePickerControllerDelegate>' from incompatible type 'ViewController *const__strong'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM