How to resolve SwiftUI.DynamicProperty on MainActor compiler warning on 6.0?

Hi! I'm running into a warning from a SwiftUI.DynamicProperty on a 6.0 development build (swift-6.0-DEVELOPMENT-SNAPSHOT-2024-03-26-a).

I am attempting to build a type (conforming to DynamicProperty) that should also be MainActor. This type with also need a custom update function. Here is a simple custom wrapper (handwaving over the orthogonal missing pieces) that shows the warning:

import SwiftUI

@MainActor struct MainProperty: DynamicProperty {
  //  Main actor-isolated instance method 'update()' cannot be used to satisfy nonisolated protocol requirement; this is an error in the Swift 6 language mode
  @MainActor func update() {
    
  }
}

Is there anything I can do about that warning? Does the warning correctly imply that this will be a legit compiler error when 6.0 ships?

I can find (at least) two examples of types adopting DynamicProperty from Apple that are also MainActor: FetchRequest and SectionedFetchRequest. What is confusing is that both FetchRequest^1 and SectionedFetchRequest^2 explicitly declare their update method to be MainActor. Is there anything missing from my Wrapper declaration that can get me what I'm looking for? Any more advice about that? Thanks!

Replies

If you’re working with Swift development toolchains, it’s best to discuss any issues you encounter on Swift Forums. DevForums tries to stay focused on the stuff that Apple has shipped (or seeded as betas).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

@eskimo Sounds good. Thanks!