我正在尝试呈现
viewcontroller,以防状态(Int
?)为零,如下所示:
guard let statusCode = status else {
DispatchQueue.main.async() {
let initViewController = self.storyboard!.instantiateViewController(withIdentifier: "SignInViewController")
self.present(initViewController, animated: false, completion: nil)
}
return
}
我想知道这是否是最佳实践,因为在呈现 View Controller 后返回没有多大意义,但在 guard
语句中它是必需的 guard
声明不能落空。
最佳答案
回答关于guard
语句和return
关键字的问题
func yourFunc() {
guard let statusCode = status else {
return DispatchQueue.main.async() { [weak self] _ in
let initViewController = self?.storyboard!.instantiateViewController(withIdentifier: "SignInViewController")
self?.present(initViewController!, animated: false, completion: nil)
}
}
}
关于ios - 在 guard 语句 swift 中呈现一个 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50266179/