Latest 3.1.4
License MIT
Platforms ios 8.0, osx 10.10, watchos 2.0, tvos 9.0



Rainbow adds text color, background color and style for console and command
line output in Swift. It is born for cross platform software logging
in terminals, working in both Apple’s platforms and Linux.


Nifty way, using the String extension, and print the colorized string:

import Rainbow

print("Red text".red)
print("Blue background".onBlue)
print("Light green text on white background".lightGreen.onWhite)

print("Cyan with bold and blinking".cyan.bold.blink)

print("Plain text".red.onYellow.bold.clearColor.clearBackgroundColor.clearStyles)

It will give you something like this:


You can also use the more verbose way if you want:

import Rainbow
let output = "The quick brown fox jumps over the lazy dog"
                .applyingCodes(, BackgroundColor.yellow, Style.bold)
print(output) // Red text on yellow, bold of course :)

Motivation and Compatibility

Thanks to the open source of Swift, developers now could write cross platform
programs with the same language. And I believe the command line software would be
the next great platform for Swift. Colorful and well organized output always
helps us to understand what happens. It is really a necessary utility to create
wonderful software.

Rainbow should work well in both OS X and Linux terminals. It is smart enough
to check whether the output is connected to a valid text terminal or not, to
decide the log should be modified or not. This could be useful when you want to
send your log to a file instead to console.

Although Rainbow is first designed for console output in terminals, you could
use it in Xcode with XcodeColors
plugin installed too. It will enable color output for better debugging
experience in Xcode.

Please notice, after Xcode 8, third party plugins in bundle (like XcodeColors) is not
supported anymore. See this.


Rainbow 3.x supports from Swift 4. If you need to use Rainbow in Swift 3, use Rainbow 2.1 instead.

Swift Package Manager

If you are developing a cross platform software in Swift,
Swift Package Manager might
be your choice for package management. Just add the url of this repo to your
Package.swift file as a dependency:

// swift-tools-version:4.0
import PackageDescription

let package = Package(
    name: "YourAwesomeSoftware",
    dependencies: [
        .package(url: "", from: "3.0.0")

Then run swift build whenever you get prepared.

You could know more information on how to use Swift Package Manager
in Apple’s official page.


Add the RainbowSwift pod to your Podfile:

source ''
platform :ios, '8.0'

pod 'RainbowSwift', '~> 3.0'

And you need to import RainbowSwift instead of Rainbow if you install it from CocoaPods.

// import Rainbow
import RainbowSwift

print("Hello CocoaPods".red)


Carthage is a decentralized dependency
manager for Cocoa application.

To integrate Rainbow with Carthage, add this to your Cartfile:

github "onevcat/Rainbow" ~> 3.0

Run carthage update to build the framework and drag the built
Rainbow.framework into your Xcode project (as well as embed it in your target
if necessary).


Follow and contact me on Twitter or
Sina Weibo. If you find an issue,
just open a ticket on it. Pull
requests are warmly welcome as well.


Rainbow is released under the MIT license. See LICENSE for details.

Latest podspec

    "name": "RainbowSwift",
    "version": "3.1.4",
    "summary": "`Rainbow` adds text color, background color and style for console and command line output in Swift.",
    "description": "`Rainbow` adds text color, background color and style for console and command nline output in Swift. It is born for cross platform software logging nin terminals, working in both Apple's platforms and Linux. Meanwhile, it is also ncompatible with [XcodeColors](, nwhich lets you colorize the Xcode debugger output as well when developing an app.",
    "homepage": "",
    "screenshots": "",
    "license": "MIT",
    "authors": {
        "onevcat": "[email protected]"
    "social_media_url": "",
    "platforms": {
        "ios": "8.0",
        "osx": "10.10",
        "watchos": "2.0",
        "tvos": "9.0"
    "source": {
        "git": "",
        "tag": "3.1.4"
    "source_files": "Sources/",
    "public_header_files": "Sources/Rainbow.h",
    "pod_target_xcconfig": {
        "SWIFT_VERSION": "4.0"
    "swift_version": "4.0",
    "static_framework": true

Pin It on Pinterest

Share This