Objective C에서 Swift로 변환해야하는 API가 있습니다. 일부 유형의 생성자 또는 초기 설정이 잘못되어 있습니다.Swift를 사용하여 Objective C에서 instancetype을 초기화하는 방법
이것은 .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 분 안에 받아 들일 것입니다) –