zoukankan      html  css  js  c++  java
  • ios Initializer element is not a compile-time constant

    在scope外进行静态变量声明,

    static const CGRect CouponListViewRect = CGRectMake(0.0,0.0,0.0,0.0);

    报错:

     Initializer element is not a compile-time constant

    原理:

    github上的回答:

    When you define a variable outside the scope of a function, that variable's value is actually written into your executable file. This means you can only use a constant value. Since you don't know everything about the runtime environment at compile time (which classes are available, what is their structure, etc.), you cannot create objective c objects until runtime, with the exception of constant strings, which are given a specific structure and guaranteed to stay that way. What you should do is initialize the variable to nil and use +initialize to create your image. initialize is a class method which will be called before any other method is called on your class.

    Example:

    NSImage*imageSegment = nil;+(void)initialize {if(!imageSegment)
            imageSegment =[[NSImage alloc] initWithContentsOfFile:@"/User/asd.jpg"];}-(id)init {
        self =[super init];
        if(self){
            // Initialization code here.
        }
    
        return self;}
  • 相关阅读:
    bzoj4543 长链剖分
    tarjan算法
    uoj36 玛里苟斯 高斯消元做法
    狄利克雷卷积
    斜率优化
    将一个工作簿拆分为多个工作表
    如何制作Excel斜线表头
    逻辑函数(IF函数)
    逻辑函数(AND,OR,NOT)
    Excel中提取英文,数值和编码(LEN函数)
  • 原文地址:https://www.cnblogs.com/so-magic/p/3755636.html
Copyright © 2011-2022 走看看