【发布时间】:2011-09-16 01:58:41
【问题描述】:
为什么这段代码不能用于从类中引用 const?
背景:我希望能够以类变量类型方法从类中引用常量值,因为这是有意义的来源。尝试找到有效地让类提供暴露常量的最佳方法。我尝试了以下方法,但它似乎不起作用,我得到“错误:在'DetailedApppointCell'类型的对象上找不到属性'titleLablePrefix'”
@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'
【问题讨论】:
-
检查this
标签: iphone objective-c ios constants class-variables