sindresorhus / Defaults

💾 Swifty and modern UserDefaults
https://swiftpackageindex.com/sindresorhus/Defaults/documentation/defaults
MIT License
1.93k stars 115 forks source link

Publishing changes from background threads is not allowed; make sure to publish values from the main thread (via operators like receive(on:)) on model updates. #152

Closed jxhug closed 8 months ago

jxhug commented 8 months ago

When using Defaults, I get this error in the SwiftUI file.

image

it's on line 16:

image

I am using the main branch for the dependency rule.

sindresorhus commented 8 months ago

I don't think this is a problem with Defaults. It is correctly marked as @MainActor, but that annotation only works when called from a concurrency context. So somewhere you are calling it from a non-main-actor context.