<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/Color/init(_:bundle:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI5ColorV_6bundleACSS_So8NSBundleCSgtcfc"
  },
  "title" : "init(_:bundle:)"
}
-->

# init(_:bundle:)

Creates a color from a color set that you indicate by name.

```
init(_ name: String, bundle: Bundle? = nil)
```

## Parameters

`name`

The name of the color resource to look up.

`bundle`

The bundle in which to search for the color resource.
If you don’t indicate a bundle, the initializer looks in your app’s
main bundle by default.

## Discussion

Use this initializer to load a color from a color set stored in an
Asset Catalog. The system determines which color within the set to use
based on the environment at render time. For example, you
can provide light and dark versions for background and foreground
colors:

![A screenshot of color sets for foreground and background colors,](images/com.apple.SwiftUI/Color-init-1@2x.png)

You can then instantiate colors by referencing the names of the assets:

```
struct Hello: View {
    var body: some View {
        ZStack {
            Color("background")
            Text("Hello, world!")
                .foregroundStyle(Color("foreground"))
        }
        .frame(width: 200, height: 100)
    }
}
```

SwiftUI renders the appropriate colors for each appearance:

![A side by side comparison of light and dark appearance screenshots](images/com.apple.SwiftUI/Color-init-2@2x.png)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)