All Projects → DreamingInBinary → ColorUp

DreamingInBinary / ColorUp

Licence: MIT License
An easy way to generate strongly typed Swift extensions for either UIColor or Color based off of your colors within the project's asset catalog.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to ColorUp

swiftui-example
SwiftUI 示例,技巧和技术集合,帮助我构建应用程序,解决问题以及了解SwiftUI的实际工作方式。
Stars: ✭ 109 (+581.25%)
Mutual labels:  uikit, swiftui
UIViewPreviewProvider
Allows displaying UIViews inside the Xcode preview canvas
Stars: ✭ 36 (+125%)
Mutual labels:  uikit, swiftui
VCore
VCore is a Swift collection containing objects, functions, and extensions that I use for my projects
Stars: ✭ 32 (+100%)
Mutual labels:  uikit, swiftui
About Swiftui
Gathering all info published, both by Apple and by others, about new framework SwiftUI.
Stars: ✭ 5,954 (+37112.5%)
Mutual labels:  uikit, swiftui
LocalConsole
In-app console and debug tools for iOS developers
Stars: ✭ 595 (+3618.75%)
Mutual labels:  uikit, swiftui
Render
UIKit a-là SwiftUI.framework [min deployment target iOS10]
Stars: ✭ 2,150 (+13337.5%)
Mutual labels:  uikit, swiftui
NavigationRouter
A router implementation designed for complex modular apps, written in Swift
Stars: ✭ 89 (+456.25%)
Mutual labels:  uikit, swiftui
NativeMarkKit
NativeMark is a flavor of Markdown designed to be rendered by native apps.
Stars: ✭ 36 (+125%)
Mutual labels:  uikit, swiftui
iOS14-Resources
A curated collection of iOS 14 projects ranging from SwiftUI to ML, AR etc.
Stars: ✭ 85 (+431.25%)
Mutual labels:  uikit, swiftui
BottomSheet
Access UISheetPresentationController in SwiftUI on iOS 15 using a simple .bottomSheet modifier.
Stars: ✭ 332 (+1975%)
Mutual labels:  uikit, swiftui
Swift Composable Architecture
A library for building applications in a consistent and understandable way, with composition, testing, and ergonomics in mind.
Stars: ✭ 5,199 (+32393.75%)
Mutual labels:  uikit, swiftui
Redux
Manage iOS App state with Redux and Async/Await :)
Stars: ✭ 18 (+12.5%)
Mutual labels:  uikit, swiftui
Swiftui Cheat Sheet
SwiftUI 2.0 Cheat Sheet
Stars: ✭ 3,417 (+21256.25%)
Mutual labels:  uikit, swiftui
SwiftCurrent
A library for managing complex workflows in Swift
Stars: ✭ 286 (+1687.5%)
Mutual labels:  uikit, swiftui
CurrencyText
Currency text field formatter available for UIKit and SwiftUI 💶✏️
Stars: ✭ 124 (+675%)
Mutual labels:  uikit, swiftui
Builder
Demonstrates SwiftUI builder patterns for UIKit and networking.
Stars: ✭ 100 (+525%)
Mutual labels:  uikit, swiftui
Movie Trailers SwiftUI
A simple app which shows the lastest movies trailers based on different genres developed using SwiftUI.
Stars: ✭ 51 (+218.75%)
Mutual labels:  uikit, swiftui
SheeKit
Customize and resize sheets in SwiftUI with SheeKit. Utilise the power of `UISheetPresentationController` and other UIKit features.
Stars: ✭ 56 (+250%)
Mutual labels:  uikit, swiftui
SwiftUIKit
📱 UIKit code that is fun to write
Stars: ✭ 71 (+343.75%)
Mutual labels:  uikit, swiftui
column-text-view-ui
📄 Column Text View is an adaptive UI component that renders text in columns, horizontally [iOS 12, UIKit, TextKit, SwiftUI].
Stars: ✭ 11 (-31.25%)
Mutual labels:  uikit, swiftui

Header Image

Motivations

At Buffer we use color catalogs extensively across our own iOS apps. But, we find that we often can mistype the names (resulting in a nil color instance) and that we have quite a few of them. This is the main problem we set out to solve. Using a generator such as this gives us the flexibility of color catalogs with the advantages of concrete function calls:

// Before 😅

// UIKit. If you mess this up or force unwrap, you could crash.
let aColor = UIColor(named: "iHopeITypedThisRight") 

// SwiftUI. If you mess this one up, you'll get primary text by default.
Text(stepToDo.backingModel.stepAbstract ?? "")
                .lineLimit(nil)
                .foregroundColor(Color("gettingStartedTextSubhead"))

// After. Strongly typed colors, no chance of typos. 😊

// UIKit
let aColor = UIColor.namedColor

// SwiftUI
Text(stepToDo.backingModel.stepAbstract ?? "")
                .lineLimit(nil)
                .foregroundColor(.gettingStartedTextSubhead)

There are other things in the pipeline for the future, such as supporting Objective-C and bundle asset catalog lookups, but this is our start!

Usage

To install ColorUp, download this repository locally to your machine.

Then navigate to its location:

$ cd location/to/colorup

From there, you must provide two things at a minimum:

  1. The fully formed file location of the asset catalog with the colors, -p.
  2. The fully formed file location of where you'd like to save the generated file, -s.

To get a feel for what you can use, run the --help command:

$ swift run ColorUp --help

Here is what a command would look like:

$ swift run ColorUp -p "users/jordan/documents/anApp/assets.xcassets/" -s "users/jordan/documents/anApp/extensions/"

If the asset catalog has one color named "MyColor", the result would look like this for UIKit:

//
//  ColorCatalogExtensions-UIKit.swift
//
//  GENERATED CODE: Any edits will be overwritten.
//  Generated on Feb 21 2020
//

import UIKit

extension UIColor {    
    class var MyColor : UIColor? {
        return UIColor(named: "MyColor")
    }
}

...and for SwiftUI:

//
//  ColorCatalogExtensions-SwiftUI.swift
//
//  GENERATED CODE: Any edits will be overwritten.
//  Generated on Feb 21 2020
//

import SwiftUI

extension Color {    
    static var MyColor : Color {
        return Color("MyColor")
    }
}

If you'd like to run ColorUp from anywhere and not have to nagivate to its location on the file system, you build it for release and move it to the executable binaries folder:

$ swift build -c release
$ cp .build/release/ColorUp /usr/local/bin/ColorUp

This allows you to just open Terminal and run it from anywhere.

Options

Xcode Project: Required

--project "path/to/project"

The complete path to the asset catalog that contains the colors you wish to generate an extension file for.

Save Location: Required

--saveLocation "path/to/save/extension"

The complete path where you wish to save the file at.

Use force unwrapping: Optional

--forceUnwrap

Use this option to generate a force-unwrapped color call. Note that SwiftUI code will ignore this option, as it's Color(name) initializer doesn't produce an optional type. Example:

class var MyColor : UIColor {
  return UIColor(named: "MyColor")!
}

versus the default:

class var MyColor : UIColor? {
  return UIColor(named: "MyColor")
}

Function Prefix: Optional

-fp "aPrefix"

Puts the supplied string in front of the generated functions. Example:

// UIKit
class var aPrefixMyColor : UIColor {
  return UIColor(named: "MyColor")!
}

// SwiftUI
static var aPrefixMyColor: Color {
  return Color("MyColor")
}

versus the default:

// UIKit
class var MyColor : UIColor? {
  return UIColor(named: "MyColor")
}

// SwiftUI
static var MyColor: Color {
  return Color("MyColor")
}

File Name: Optional

--fileName "GeneratedColors"

The name of the generated file containing the extensions. Defaults to ColorCatalogExtensions-UIKit.swift for UIKit, and ColorCatalogExtensions-SwiftUI.swift for SwiftUI.

Generate SwiftUI Code: Optional

--SwiftUI 

A boolean, if present the generated code is for SwiftUI's Color type. If not, it'll default to UIKit and UIColor.

Contributing

ColorUp welcomes anyone to contribute. Here's a quick start guide:

1. Clone the project

$ git clone https://github.com/DreamingInBinary/ColorUp.git

2. Generate an Xcode Project

$ cd path/to/colorup
$ swift package generate-xcodeproj

3. Build the Project

$ swift build 

4. Run It

$ swift run ColorUp --saveLocation "path/to/save/extension" --project "path/to/project"

I find it's much easier to run it locally from an Xcode project and use the CommandLineUtil class to provide debug values using debugValues().

For development, all the files you'll need to use are within ColorUpCore:

  1. ColorUp.swift runs the actual program, and has the code to generate the file.
  2. CommandLineUtil.swift houses logic to get input from the command the user has run, and houses them within FileGenOptions.

Any questions? Feel free to reach out to on Twitter or open an issue!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].