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


As an example that I’ve this pretty minimal implementation of customized configuration and content material view in my app:

struct ExampleContentConfiguration {
  let identify: 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

last 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. However, UIView (and its subclasses) are marked as @MainActor. So once I set the Strict Concurrency Checking construct setting to Full, Xcode experiences two points on the marked strains:

  1. Name to primary actor-isolated initializer ‘init(configuration:)’ in a synchronous nonisolated context.
  2. Predominant 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 might these sorts implement these protocols whereas adhering to the strict concurrency guidelines?


Leave a Reply