ios – Are customized UIContentView / UIContentConfiguration implementations incompatible with Swift strict concurrency?

[ad_1]

For instance that I’ve this pretty minimal implementation of customized configuration and content material view in my app:

struct ExampleContentConfiguration {
  let title: String
  let rating: Int
}

extension ExampleContentConfiguration: UIContentConfiguration {
  func makeContentView() -> UIView & UIContentView {
    return ExampleContentView(configuration: self)  // [1]
  }
  
  func up to date(for state: UIConfigurationState) -> ExampleContentConfiguration {
    return self
  }
}

remaining class ExampleContentView: UIView, UIContentView {
  var configuration: UIContentConfiguration  // [2]
  
  init(configuration: ExampleContentConfiguration) {
    self.configuration = configuration
    tremendous.init(body: .zero)
  }
  
  required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been carried out")
  }
}

The 2 protocols that underlie this haven’t any concurrency annotations. Alternatively, UIView (and its subclasses) are marked as @MainActor. So once I set the Strict Concurrency Checking construct setting to Full, Xcode studies two points on the marked strains:

  1. Name to essential actor-isolated initializer ‘init(configuration:)’ in a synchronous nonisolated context.
  2. Most important actor-isolated property ‘configuration’ can’t be used to fulfill nonisolated protocol requirement.

(Confusingly, if I have a look at the generated interface for UIListContentView, its configuration property has a @MainActor attribute.)

What am I lacking right here? How may these varieties implement these protocols whereas adhering to the strict concurrency guidelines?

[ad_2]

Leave a Reply