initializer element is not a comply-time constant

来源:互联网 发布:多个表格数据求和 编辑:程序博客网 时间:2024/05/21 14:07

在Xcode中定义全局静态变/常量如下所示,会报出initializer element is not a comply-time constant error。

#define myWidth 50#define KWindowsH [UIScreen mainScreen].bounds.size.heightstatic CGFloat const testWidth = KWindowsH;//此处改成myWidth或者常量则编译通过。


初始化一个全局静态变/常量,需要一个常量。


屏幕高度需要在运行期计算,所以在编译期Xcode会报错


iOS编译过程的原理和应用