8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

guard let self = selfするとLLDBでpo等できない問題が直った (Xcode 11 beta)

Posted at

Xcode 10までは以下のようなコードを書くと、closure内でselfを再定義するせいでLLDBが思うように変数を認識してくれなくなる。

class SomeClass {
    private func someFunction(someClosure: ()->Void) {
        someClosure()
    }

    func doTask() {
        let greeting = "Hi"
        someFunction { [weak self] in
            guard let self = self else { return }
            // ここで po greeting とかしてもちゃんと出力されない
            // (frame variable greeting だと問題ないけど)
            print(greeting) //-> "Hi"
        }
    }
}

こんな感じのエラーが出てた:

error: warning: <EXPR>:12:9: warning: initialization of variable '$__lldb_error_result' was never used; consider replacing with assignment to '_' or removing it
    var $__lldb_error_result = __lldb_tmp_error
    ~~~~^~~~~~~~~~~~~~~~~~~~
    _

error: <EXPR>:19:5: error: value of type 'SomeClass' has no member '$__lldb_wrapped_expr_4'
    $__lldb_injected_self.$__lldb_wrapped_expr_4(
    ^~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~

報告もある:[SR-6156] LLDB: warning: initialization of variable '$__lldb_error_result' - Swift

self = self じゃなくて strongSelf = self とかにすればこの問題は起きないけど、せっかくだから self = self がいいし・・・っていうか今更書き換えるのやだし・・・

と思ってたら、この間リリースされたXcode 11 (beta) ではそれが直ってます!

Xcode 11 Beta Release Notes | Apple Developer Documentation:

Redeclaring self in Swift code works properly with LLDB. (39611934)

🙌🙌🙌

8
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?