我试图提供一个viewcontroller以防万一,状态(一个Int?)是零,如下所示: guard let statusCode = status else { DispatchQueue.main.async() { let initViewController = self.storyboard!.instantiateViewController(withIdentifier:
guard let statusCode = status else {
DispatchQueue.main.async() {
let initViewController = self.storyboard!.instantiateViewController(withIdentifier: "SignInViewController")
self.present(initViewController, animated: false, completion: nil)
}
return
}
我想知道这是否是最好的做法,因为在呈现一个viewcontroller之后返回并没有多大意义,但是在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)
}
}
}
