即使使用 NS_BUILD_32_LIKE_64 宏也无法设置边界
我的项目在调试模式下编译并运行正常,但是当我切换到发行版 x86_64 编译时,由于尝试使用 NSRect 设置边界,我收到编译器错误。 (错误显示“setBounds 的参数 1 的类型不兼容”。)
我认为有很多帖子建议在 Cocoa(Foundation)导入上方添加 NS_BUILD_32_LIKE_64 宏定义,以便 NSGeometry 中的“if NS_BUILD_32_LIKE_64”语言.h 将为 true 并且将使用必要的 typedef。所以我将宏定义添加到有问题的类的 h 文件中:
#define NS_BUILD_32_LIKE_64 1
#import <Cocoa/Cocoa.h>
并且我仍然遇到相同的编译错误。
我还尝试显式从 NSRect 转换为 CGRect,这样就可以代替 this 。 。 。
// rectIncomingSource is an NSRect
calayer.bounds = rectIncomingSource;
。 。 。我写了这个:
calayer.bounds = CGRectMake(rectIncomingSource.origin.x, rectIncomingSource.origin.y, rectIncomingSource.size.width, rectIncomingSource.size.height);
同样的错误。
为什么设定界限是唯一的问题?根据 Apple 文档,NSInteger 和 NSUInteger 是主要的转换问题,我在各处都使用它们,但编译器不会抱怨它们。那么为什么它会在边界上窒息呢?
我可能在这里遗漏了一些非常简单的东西——为此我向巫师们道歉。对盲人有什么帮助吗?
My project compiles and runs OK in debug mode, but when I switch to release x86_64 compiling, I get compiler errors for attempts to setBounds using NSRect. (The errors read “incompatible type for argument 1 of setBounds”.)
There are lots of posts which I take to be suggesting to add the NS_BUILD_32_LIKE_64 macro definition above the Cocoa (Foundation) import, so that the “if NS_BUILD_32_LIKE_64” language in NSGeometry.h will be true and the necesseary typedefs will be used. So I added the macro definition to the h file of the offending class:
#define NS_BUILD_32_LIKE_64 1
#import <Cocoa/Cocoa.h>
And I still get the same compile errors.
I also tried converting explicitly from NSRect to CGRect, so that instead of this . . .
// rectIncomingSource is an NSRect
calayer.bounds = rectIncomingSource;
. . . I wrote this:
calayer.bounds = CGRectMake(rectIncomingSource.origin.x, rectIncomingSource.origin.y, rectIncomingSource.size.width, rectIncomingSource.size.height);
Same errors.
And why would setting bounds be the only problem? Per Apple docs, NSInteger and NSUInteger are the main conversion problem, and I use them all over the place, but the compiler doesn’t complain about them. So why would it choke on bounds?
I’m probably missing something really simple here — for which I apologize to the wizards. Any help for the blind?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目标信息窗口给了我解决这个问题的线索:
我将 NS_BUILD_32_LIKE_64 定义放在特定类的 h 文件中。它应该位于前缀头文件中,该文件具有 pch 扩展名,通常位于项目的“其他源”中。
嗯,是的,我想这是显而易见的。但也许其他一些预处理器新手会发现这个澄清很有帮助,所以我不会删除这个问题。
我仍然不明白为什么设置界限应该是唯一的问题。也许与核心动画有关?
The target info window gave me the clue to figure this out:
I was putting the NS_BUILD_32_LIKE_64 define in a particular class's h file. It should have been in the prefix header file, the one with the pch extension that usually resides in the project's "Other Sources."
Well, yeah, I suppose this was obvious. But maybe some other preprocessor neophyte will find this clarification helpful, so I won't delete the question.
And I still don't understand why setting bounds should have been the only problem. Maybe something to do with core animation?