我可以定义全局的字符串是这样的:如何在objective-C中定义非字符串常量?
// .h
extern NSString * const myString;
// .m
NSString * const myString = @"String";
现在我需要同样定义的UIColor,我该怎么办呢?
我想:
// .h
extern UIColor * const myColor;
// .m
UIColor * const myColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0];
但它不工作,我越来越error: initializer element is not constant
感谢
类别(来自接受答案中的链接答案)在这里是过度杀伤。请看这个问题:创建一个字典对象:http://stackoverflow.com/questions/3855556/creating-a-constant-dictionary-object/ – 2010-10-25 17:14:54
不知道到底为什么会发生,但[this](http:// stackoverflow.com/questions/2718507/how-do-i-define-constant-values-of-uicolor)问题可能会帮助你解决问题。 – Norling 2010-10-25 15:46:31