错误:缺少预期返回"UIViewController"的闭包中的返回(Xcode,Swift,iOS 13) [英] Error: Missing return in a closure expected to return 'UIViewController' (Xcode, Swift, iOS 13)

查看:179
本文介绍了错误:缺少预期返回"UIViewController"的闭包中的返回(Xcode,Swift,iOS 13)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了错误:粗体行上的缺少预期返回'UIViewController'的闭包中的返回".我怎样才能解决这个问题?谢谢!!

I'm getting the error: "Missing return in a closure expected to return 'UIViewController'" on the bolded line. How can I fix this? Thank you!!

   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


    }

推荐答案

您只需要在闭包内部返回 ViewController

you just need to return ViewController inside closure

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
    }

这篇关于错误:缺少预期返回"UIViewController"的闭包中的返回(Xcode,Swift,iOS 13)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆