【问题标题】:Error: Missing return in a closure expected to return 'UIViewController' (Xcode, Swift, iOS 13)错误:预期返回“UIViewController”的闭包中缺少返回(Xcode、Swift、iOS 13)
【发布时间】:2019-12-27 03:52:13
【问题描述】:

我收到错误消息:“在预期返回 '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


    }

【问题讨论】:

    标签: swift xcode ios13 swift5 swift5.1


    【解决方案1】:

    你只需要在闭包中返回 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
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-08
      • 1970-01-01
      • 1970-01-01
      • 2019-05-14
      • 2018-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多