ios中怎么定义数组常量?
巴扎黑
巴扎黑 2017-04-17 16:20:33
0
3
480
巴扎黑
巴扎黑

reply all(3)
小葫芦

It can be like this

static NSString const *imgArr[3] = {
    @"引导页1",
    @"引导页2",
    @"引导页3"
};
大家讲道理

It involves runtime.
Except for the NSString type, it is not allowed to declare a ‘static global constant type OC object’ outside a method.
The static const NSArray *imgArr you declared does not know the type of imgArr when 'compiling'. PS: A constant of global constant type, static const is a constant that the system needs to determine when compiling. What type is it? However, the type of OC object is determined at 'runtime'. Different from the determination time of basic data types, it is pushed from compilation time to runtime (the reason why OC supports polymorphism).
Except for NSString, NSString is a special data type with special storage structure and permissions to ensure that the system can recognize it.
If you want to understand it more deeply, you need to learn the runtime mechanism of OC.

Peter_Zhu

const NSArray * arr = @[@"123",@"456"];
Written like this, it is already a constant array

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template