为什么此代码不能用于从类引用常量?为什么此代码不能用于从类引用常量?
背景:我希望能够在类变量类型的方法中引用类中的常量值,因为这是源代码有意义的地方。尝试找到有效让班级提供暴露常数的最佳方式。我试过以下,但它似乎没有工作,我得到:
@interface DetailedAppointCell : UITableViewCell {
}
extern NSString * const titleLablePrefix;
@end
#import "DetailedAppointCell.h"
@implementation DetailedAppointCell
NSString * const titleLablePrefix = @"TITLE: ";
@end
// usage from another class which imports
NSString *str = DetailedAppointCell.titleLablePrefix; // ERROR: property 'titleLablePrefix' not found on object of type 'DetailedAppointCell'
check [this](http://stackoverflow.com/questions/538996/constants-in-objective-c) – 2011-06-16 05:51:54