Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why are most SwiftUI Views non-sendable?

Why are most SwiftUI types (like Color or Text) non-sendable? Is there a specific reason for this? Isn’t that kind of the point of SwiftUI views? Or am I missing something?

struct Test: Sendable {
  let color: Color // Warning: Stored property 'color' of 'Sendable'-conforming struct 'Test' has non-sendable type 'Color'
}

I want to store colors in a struct that needs to be sendable, but I get this warning (with concurrency checking set to complete). I don’t just want to mark it @unchecked Sendable without knowing if it’s actually safe to do so.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Color is a representation of a color. Which is a View a type that represents part of your app’s user interface and provides modifiers that you use to configure views.

It isn’t really meant to be passed around. It doesn’t have any value to any other layers in the application it is strictly for presentation.

UIColor is an object that stores color data and sometimes opacity. This can be used across layers for different purposes.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading