Capture of 'self' in a `@Sendable` closure

3.4k Views Asked by At

My app uses the following view controller with an IBAction.
When the action is triggered by some button, the button is disabled, and some background processing is started.
When background processing is finished, the button is enabled again, which has to be done on the main thread.

final class DebugViewController: UIViewController {
  button.isEnabled = false
  // …
  @IBAction func action(_ sender: Any) {
    // …
    Task {
      // some background processing
      DispatchQueue.main.async {
        self.button.isEnabled = true
      }
    }
    // …
  }
}

During a build, the following warning is shown at the statement self.button.isEnabled = true:

Capture of 'self' with non-sendable type 'DebugViewController' in a `@Sendable` closure  

I could avoid this warning by declaring the DebugViewController as

final class DebugViewController: UIViewController, @unchecked Sendable {  

However, when I analyze instead of build the code, I get now the following error at this line:

Redundant conformance of 'DebugViewController' to protocol 'Sendable'  

Thus I am a little confused:

  • Is every UIViewController Sendable, as the "Redundant conformance" error suggests?
  • If so, why do I get the warning that DebugViewController is not Sendable?
  • If a UIViewController is not Sendable, why do I get then a Redundant conformance" error?

And eventually, how to do it correctly?

1

There are 1 best solutions below

0
On BEST ANSWER

This was apparently a bug in Xcode 13.3 Beta 2. In the released Version 13.3 (13E113), no warning is shown.