Does anyone know how to conform this class to identifiable? It's a viewmodel called from SwiftUI. It works if I drop the @MainActor but I wonder whether this will not cause any issues later on... The code follows a @pointfreeco example (which also drop the MainActor)...

#swift #swiftlang #iOSDev

@tjadejong You have a number of options. If you are using Xcode 26 (Swift 6.2), you can use an isolated conformance. Put `@MainActor` before the protocol. (And tell me if it works!)

If not, you can use a preconcurrency conformance. This is a *slight* hack, but I think it is the best option overall. You can learn about it here.

https://www.massicotte.org/preconcurrency

So how does this whole @preconcurrency thing work?

I consistently find the @preconcurrency attribute to be confusing. But, I’m tired of that. Let’s just, once and for all, get a better handle how to use this thing.

massicotte.org
@mattiem thanks! Not using Xcode 26 yet... I read about adding the @preconcurrency attribute but was not sure it was the right way to go... What would be the best in this case though? Removing the MainActor annotation (which also feels like a hack) or adding the preconcurrency?

@tjadejong This is an Observable. It is has main thread-only state.

If it is not participating in concurrency at all (no async methods, no use of Task), you can remove the MainActor annotation.

Otherwise preconcurrency for Xcode 16 compatibility.