此代码是否已从 objective-c 正确翻译为 swift?
Is this code correctly translated from objective-c to swift?
您好,我正在尝试将此代码从 Objective-c 转换为 Swift。任何人都可以确认这是否正确或是否需要更改。
- (UIStoryboard *)grabStoryboard {
UIStoryboard *storyboard;
// detect the height of our screen
int height = [UIScreen mainScreen].bounds.size.height;
if (height == 480) {
storyboard = [UIStoryboard storyboardWithName:@"Main3.5" bundle:nil];
} else if (height == 568) {
storyboard = [UIStoryboard storyboardWithName:@"Main4.0" bundle:nil];
}else {
storyboard = [UIStoryboard storyboardWithName:@"Main7.0" bundle:nil];
}
return storyboard;
}
这是我目前所拥有的。
func grabStoryboard() {
var storyboard = UIStoryboard()
var height = UIScreen .mainScreen().bounds.size.height
if(height == 480){
storyboard = UIStoryboard(name: "3.5", bundle: nil)
} else if(height == 568){
storyboard = UIStoryboard(name: "4.0", bundle: nil)
}else{
storyboard = UIStoryboard(name: "7.0", bundle: nil)
}
}
我还需要翻译方面的帮助
UIStoryboard *storyboard = [self grabStoryboard];
self.window.rootViewController = [storyboard instantiateInitialViewController];
[self.window makeKeyAndVisible];
和
return storyboard;
我不明白你的问题,但你的swift方法应该是这样的
func grabStoryboard()-> UIStoryboard {
var storyboard:UIStoryboard?
var height = UIScreen .mainScreen().bounds.size.height
if(height == 480){
storyboard = UIStoryboard(name: "3.5", bundle: nil)
} else if(height == 568){
storyboard = UIStoryboard(name: "4.0", bundle: nil)
}else{
storyboard = UIStoryboard(name: "7.0", bundle: nil)
}
return storyboard!;
}
很好的尝试。但是在 swift.
中应该没有什么改变来更正你的代码
let storyboard:UIStoryboard = self.grabStoryboard()
self.window?.rootViewController = storyboard.instantiateInitialViewController() as? UIViewController
self.window?.makeKeyAndVisible()
获取故事板的方法如下:
func grabStoryboard() -> UIStoryboard {
var storyboard = UIStoryboard()
var height = UIScreen .mainScreen().bounds.size.height
if(height == 480) {
storyboard = UIStoryboard(name: "3.5", bundle: nil)
} else if(height == 568) {
storyboard = UIStoryboard(name: "4.0", bundle: nil)
} else {
storyboard = UIStoryboard(name: "7.0", bundle: nil)
}
return storyboard
}
您好,我正在尝试将此代码从 Objective-c 转换为 Swift。任何人都可以确认这是否正确或是否需要更改。
- (UIStoryboard *)grabStoryboard {
UIStoryboard *storyboard;
// detect the height of our screen
int height = [UIScreen mainScreen].bounds.size.height;
if (height == 480) {
storyboard = [UIStoryboard storyboardWithName:@"Main3.5" bundle:nil];
} else if (height == 568) {
storyboard = [UIStoryboard storyboardWithName:@"Main4.0" bundle:nil];
}else {
storyboard = [UIStoryboard storyboardWithName:@"Main7.0" bundle:nil];
}
return storyboard;
}
这是我目前所拥有的。
func grabStoryboard() {
var storyboard = UIStoryboard()
var height = UIScreen .mainScreen().bounds.size.height
if(height == 480){
storyboard = UIStoryboard(name: "3.5", bundle: nil)
} else if(height == 568){
storyboard = UIStoryboard(name: "4.0", bundle: nil)
}else{
storyboard = UIStoryboard(name: "7.0", bundle: nil)
}
}
我还需要翻译方面的帮助
UIStoryboard *storyboard = [self grabStoryboard];
self.window.rootViewController = [storyboard instantiateInitialViewController];
[self.window makeKeyAndVisible];
和
return storyboard;
我不明白你的问题,但你的swift方法应该是这样的
func grabStoryboard()-> UIStoryboard {
var storyboard:UIStoryboard?
var height = UIScreen .mainScreen().bounds.size.height
if(height == 480){
storyboard = UIStoryboard(name: "3.5", bundle: nil)
} else if(height == 568){
storyboard = UIStoryboard(name: "4.0", bundle: nil)
}else{
storyboard = UIStoryboard(name: "7.0", bundle: nil)
}
return storyboard!;
}
很好的尝试。但是在 swift.
中应该没有什么改变来更正你的代码let storyboard:UIStoryboard = self.grabStoryboard()
self.window?.rootViewController = storyboard.instantiateInitialViewController() as? UIViewController
self.window?.makeKeyAndVisible()
获取故事板的方法如下:
func grabStoryboard() -> UIStoryboard {
var storyboard = UIStoryboard()
var height = UIScreen .mainScreen().bounds.size.height
if(height == 480) {
storyboard = UIStoryboard(name: "3.5", bundle: nil)
} else if(height == 568) {
storyboard = UIStoryboard(name: "4.0", bundle: nil)
} else {
storyboard = UIStoryboard(name: "7.0", bundle: nil)
}
return storyboard
}