未连接设备时,布尔上的Xcode编译错误 [英] Xcode compile error on bool when device not connected

查看:71
本文介绍了未连接设备时,布尔上的Xcode编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码片段制作一个简单的动画:

I am trying to do a simple animation by using this snippet:

[UIView animateWithDuration:2.0
                      delay:0.0
                    options: UIViewAnimationOptionCurveEaseInOut
                 animations:^{
                    [self.view setAlpha:0.7f];

                 }
                 completion:^(BOOL finished){
                     if(finished)  NSLog(@"Finished !!!!!");
                     // do any stuff here if you want
                 }];

但是XCode给我一个错误说明:

But XCode is giving me an error stating:

不兼容的块指针类型将'void(^)(uint_8t)'发送给 类型为"void(^)(BOOL)'"的参数.

"Incompatibile block pointer types sending 'void(^)(uint_8t)' to parameter of type 'void(^)(BOOL)'".

如果我尝试将'BOOL'更改为'bool',则在iPad Air上编译时代码可以正常工作,但是当我断开iPad并尝试使用模拟器时,会遇到相同的错误,但类型不同:

If I try changing the 'BOOL' to 'bool', then the code works fine when compiling on an iPad Air, but then when I disconnect the iPad and try the simulator, I get the same error, but with different types:

不兼容的块指针类型将'void(^)(bool)'发送到 类型为"void(^)(BOOL)'"的参数.

"Incompatibile block pointer types sending 'void(^)(bool)' to parameter of type 'void(^)(BOOL)'".

在我看来,这很奇怪,因为它似乎对很多人都有用,并且是相当标准的代码.是什么导致这种现象?

In my opinion this is weird, as it is a code snippet that seems to work for many people, and is a rather standard piece of code. What could be causing this behavior?

P.S.我还会在-(void)viewWillDisappear:(bool)animateated方法中收到有关不兼容类型的警告.当我连接iPad时,它们也会消失,而当断开连接时,它们会再次出现.

P.S. I also get warnings of incompatibile types in the - (void)viewWillDisappear:(bool)animated method. They also dissapear when I connect the iPad, and appear again when it is disconnected.

---- 此代码甚至会导致错误:

---- This code even causes errors:

[searchArray enumerateObjectsUsingBlock:^(NSString *key, NSUInteger idx, BOOL *stop)
     {
         address = addresses[key];
         if(address) *stop = YES;
     } ];

也在BOOL字段上.而且错误是相同的,相互冲突的参数类型.

Also on the BOOL field. And the errors are the same, conflicting parameter types.

推荐答案

BOOL是另一种类型,具体取决于您是针对32位编译还是针对64位编译.使用了不同的类型,例如Bool,bool,Boolean和其他类型,请确保在所有地方都使用相同的类型.

BOOL is a different type, depending on whether you compile for 32 bit or for 64 bit. There are different types used like Bool, bool, Boolean plus probably others - make sure that you use the same type everywhere.

插入设备意味着将为您的设备而不是为模拟器编译代码,因此这可以在32位和64位之间更改并触发问题.

Plugging in your device means that code will be compiled for your device, and not for the simulator, so this can change between 32 and 64 bit and trigger the problem.

我还要检查代码中是否存在BOOL的typedef或#define.双击代码中的BOOL,单击鼠标右键,然后单击显示定义".

I'd also check if there is a typedef or #define for BOOL somewhere in your code. Double-click on BOOL in your code, right-click and "Show definition".

这篇关于未连接设备时,布尔上的Xcode编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆