Home > front end >  Why are most SwiftUI Views non-sendable?
Why are most SwiftUI Views non-sendable?

Time:12-30

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.

CodePudding user response:

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.

  • Related