我想分类应该只初始化一次并返回一些第一次计算的值。下面是正确的方法吗?
@property (nonatomic, retain) NSString *userAgent;
@implementation UserAgent
@synthesize userAgent = _userAgent;
+ (NSString *) userAgentString
{
UserAgent *thisClass;
if(self == nil)
{
thisClass = [[UserAgent alloc] init];
}
if (thisClass.userAgent == nil)
{
return @"not initialized";
}
return thisClass.userAgent;
}