我有一个API,我必须将它从Objective C转换为Swift。 我坚持使用某种类型的构造函数或初始化我不太了解。如何用Swift从Objective C启动实例类型
这是.h文件如何:
+ (instancetype) newProductionInstance;
+ (instancetype) newDemoInstance;
这是文件的.m怎么是:
+ (instancetype) newProductionInstance
{
return [[self alloc] initWithBaseURLString:productionURL];
}
+ (instancetype) newDemoInstance
{
return [[self alloc] initWithBaseURLString:demoURL];
}
- (instancetype)initWithBaseURLString:(NSString *)urlString
{
if (self = [self init])
{
_apiURL = [NSURL URLWithString:urlString];
}
return self;
}
这是呼叫自己要我翻译的主要文件:
mobileApi = [MobileAPI newDemoInstance];
所以我只想最后一行转换为斯威夫特2
在此先感谢。
感谢那些工作。 (我会在4分钟内接受) –