斯威夫特“后卫让”解开失败

时间:2016-04-22 11:00:23

标签: xcode swift var guard let

无法使用Swift 2.2,Xcode版本7.3(7D175)

打开可选类型 “警卫让”失败了 "guard let" failed

但是“guard var”有效 But "guard let" works

请帮忙! 这是怎么回事?

EDIT1

    let localPresenter = presenter
    let localDataSource = dataSource
    let configurator: ViewControllerConfigurator = { inputView in
        let a = inputView as? ChatTableViewController
        guard var chatListController = a else {
            throw ApplicationErrors.ModuleConfigureError.WrongViewInput
        }
        localPresenter.view = chatListController
        chatListController.presenter = localPresenter
        chatListController.tableView.dataSource = localDataSource
    }

EDIT2 这段代码工作正常:

        let localPresenter = presenter
        let localDataSource = dataSource
        let configurator: ViewControllerConfigurator = { inputView in
            let a = inputView as? ChatTableViewController
            if let chatListController = a {
                localPresenter.view = chatListController
                chatListController.presenter = localPresenter
                chatListController.tableView.dataSource = localDataSource
            } else {
                throw ApplicationErrors.ModuleConfigureError.WrongViewInput
            }
        }

1 个答案:

答案 0 :(得分:0)

看起来它是lldb中的一个错误。 如果我在“guard”的行上设置断点,那么“guard”会失败: enter image description here

但是,如果我将此断点移动到保护块之外,则代码可以正常工作: enter image description here