아래 코드를 Swift로 번역 할 때 도움이 필요합니다.스위프트 : 구문 번역
목표 - C 코드 (좋은 작품) :
- (UIViewController *)getViewControllerFromStoryboard:(NSString *)storyboardName sceneName:(NSString*)sceneName iconName:(NSString*)icon title:(NSString*)title
{
UIStoryboard *sb = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:sceneName];
UIImage *tabIcon = [UIImage imageNamed:icon];
vc.tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:tabIcon selectedImage:nil];
vc.title = NSLocalizedString(title,nil);
return vc;
}
번역 스위프트로 :
func getViewControllerFromStoryBoar(storyboardName: String, sceneName: String, iconName: String, title: String) -> UIViewController{
let sb : UIStoryboard = UIStoryboard(name: storyboardName, bundle: nil)
let vc = sb.instantiateViewControllerWithIdentifier(sceneName) //Warning A
let tabIcon : UIImage = UIImage(named: iconName)!
vc.tabBarItem = UITabBarItem(initWithTitle:title, image:tabIcon) //Error A
vc.title = title //Error B
return vc as UIViewController
}
경고의 '! AnyObject' 상수 'VC를'유형을 가지고 추론하는 예기치 않은 경우 일 수 있습니다. 이유 'AnyObject!' ? 이 오류를 해결하는 것
오류 A :은 'VC'에서 'tabBarItem'에 할당 할 수 없습니다
오류 B :은 'VC'
I 돈의 '제목'에 할당 할 수 없습니다 위의 두 가지 오류를 이해하지 못합니다.