0

Can't unwrap optional type with Swift 2.2, Xcode Version 7.3 (7D175)

"guard let" failed "guard let" failed

But "guard var" works But "guard let" works

Please, help! What is going on here?

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 This code works fine:

        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
            }
        }
adnako
  • 1,287
  • 2
  • 20
  • 30

1 Answers1

0

Looks like it is a bug in lldb. If I set a breakpoint on the line with "guard" then "guard" fails: enter image description here

But if I move this breakpoint past the guard block the code works fine: enter image description here

adnako
  • 1,287
  • 2
  • 20
  • 30
  • It's not a bug, it's how it works. :) The breakpoint is a barrier, a stop sign: the execution runs *until it encounters the breakpoint* so if you put the stop *on* a line, the app pauses *just before this line*. – Eric Aya Apr 22 '16 at 11:38
  • I'm sorry, but why it works this way that when I set a breakpoint the code fails? What to read about his behavior? I know the breakpoint far back in the past was an IRQ to stop a CPU on an instruction, but looks like there is something happened here with register values therefore the code works wrong. Isn't it? – adnako Apr 22 '16 at 11:45
  • In physics it's called "observer effect". – adnako Apr 22 '16 at 11:49
  • @adnako have you tried not using breakpoints but `print` statements instead? – Tim Vermeulen Apr 22 '16 at 12:41
  • I'd like to see entire picture of program state, `print` statement is for simple logging. – adnako Apr 22 '16 at 14:08