Mixer 1.0.0

Mixer 1.0.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Feb 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Beat Richartz.



Mixer 1.0.0

  • By
  • Beat Richartz

Mixer

Centralize your color definitions in a CSV file & easily share them for people to edit.

Default Setup

Mixer will look for a file named Colors.csv in the specified bundle or at the specified path. The contents of the file should look like this. It is important to keep the headers as shown, otherwise Mixer will not be able to read the file.

For the colors you’d like to use in your project, define a class which conforms to the protocol MixerColor. The only requirement of that protocol is that the object responds to the property name, so for example it could look like:

enum Color: String, MixerColor {
    case Blue = "Blue"
    case Red = "Red"

    var name: String { return rawValue }
}

Where "Blue" corresponds to the name of a color in the csv file.

Configuring

Mixer can be passed a MixerConfiguration object where you can specify another path to your colors file.

Using Mixer

Pass the bundle to initialize. Mixer will look up the Colors file in the bundle and cache it for subsequent initializations in the same process:

let bundle = Bundle(forClass: self.dynamicType)
let mixer = Mixer(bundle: bundle)

Typically, all you will then use is the colorFor method, which you can use in two ways:

Using your color definition

Remember the definition of Color from above? This is how to get a color according to your definitions:

let color = mixer.colorFor(Color.Blue)

Using a string

This is a convenience method to be able to use Mixer with @IBDesignable / @IBInspectable. Since @IBInspectable does not yet work with enum types, you can use the version of colorFor without a type check like so:

let color = mixer.colorFor("Blue")

For an example involving @IBDesignable, go to the wiki

Contributions

Yes please!