Swiftpack.co -  nbasham/BlackLabsSwiftUIColor as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
SwiftUI Color support for hex, web color constants, random, and UIColor constants.
.package(url: "https://github.com/nbasham/BlackLabsSwiftUIColor.git", from: "1.06")



Swift Package Manager

If you are using Xcode 11 or later:

  1. Click File
  2. Swift Packages
  3. Add Package Dependency...
  4. Enter: https://github.com/nbasham/BlackLabsSwiftUIColor/


Works with UIColor and Color. Color is determined at runtime. This implementation grabs the current .light/.dark color and saves it, the color being saved will loose the .light/.dark color not currently in use. UIColor uses UserDefaults.standard.uicolor(forKey) and UserDefaults.standard.uicolors(forKey) API.

let color = Color.red
UserDefaults.standard.set(color, forKey: "key")
if let savedColor: Color = UserDefaults.standard.color(forKey: "key") {
print("Loaded Color from UserDefaults: \(savedColor.hex)")

let colors: [Color] = [.red, .orange, .pink]
UserDefaults.standard.set(colors, forKey: "arraykey")
if let savedColors: [Color] = UserDefaults.standard.colors(forKey: "arraykey") {
print("Loaded [Color] from UserDefaults: \(savedColors.map { $0.hexWithAlpha })")

Example project

Example project demonstrating usage.

Readme image


Stars: 5
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Added web colors test.
19 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API