Error: Missing return in a closure expected to return 'UIViewController' (Xcode, Swift, iOS 13)

Error: Missing return in a closure expected to return 'UIViewController' (Xcode, Swift, iOS 13)

我收到错误:"Missing return in a closure expected to return 'UIViewController'" 在粗体行。我怎样才能解决这个问题?谢谢!!

   Var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    FirebaseApp.configure()


let hasSession = UserDefaults.standard.value(forKey: "UserHasSubmittedPassword") as? Bool
     let vc: UIViewController = {
               if let hasSession = hasSession, hasSession == true {
                    // next vc you want to show
                } else {
                    // enter password vc
                }
      **}()**

      let navigationController = UINavigationController(rootViewController: vc)
      window?.rootViewController = navigationController
      window?.makeKeyAndVisible()
      return true


    }

你只需要 return ViewController 里面的闭包

Var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    FirebaseApp.configure()

let Myvc = UIViewController()

let hasSession = UserDefaults.standard.value(forKey: "UserHasSubmittedPassword") as? Bool
     let vc: UIViewController = {
               if let hasSession = hasSession, hasSession == true {
                    // next vc you want to show
                       return Myvc
                } else {
                    // enter password vc
                        return Myvc
                }
      **}()**

      let navigationController = UINavigationController(rootViewController: vc)
      window?.rootViewController = navigationController
      window?.makeKeyAndVisible()
      return true
    }