gpt4 book ai didi

iphone - 为什么这段代码不能用于从类中引用常量?

转载 作者:行者123 更新时间:2023-11-28 20:46:00 25 4
gpt4 key购买 nike

为什么这段代码不能用于从类中引用常量?

背景:我希望能够在类变量类型方法中引用类中的常量值,因为这是获取源代码有意义的地方。尝试找到有效地让类提供公开常量的最佳方法。我尝试了以下但它似乎不起作用,我得到“错误:在类型为‘DetailedAppointCell’的对象上找不到属性‘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'

最佳答案

如果您的外部链接正确,您可以直接使用 NSString *str = titleLablePrefix;

关于iphone - 为什么这段代码不能用于从类中引用常量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6367434/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com