Skip to content

Instantly share code, notes, and snippets.

@andrewgrant
Created June 30, 2015 03:42
Show Gist options
  • Save andrewgrant/a4c076c9e3664f8e6e5f to your computer and use it in GitHub Desktop.
Save andrewgrant/a4c076c9e3664f8e6e5f to your computer and use it in GitHub Desktop.

Revisions

  1. andrewgrant renamed this gist Jun 30, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. andrewgrant created this gist Jun 30, 2015.
    16 changes: 16 additions & 0 deletions gistfile1.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    required init(coder aDecoder: NSCoder) {

    let colorArray = aDecoder.decodeObjectForKey("colors") as! [CGFloat]
    self.CGColor = CGColorCreate(CGColorSpaceCreateDeviceRGB(), colorArray)

    super.init()
    }

    func encodeWithCoder(aCoder: NSCoder) {

    let colors = CGColorGetComponents(CGColor)
    let colorBuffer = UnsafeBufferPointer(start: colors, count: 4)
    let colorArray = [CGFloat](colorBuffer)

    aCoder.encodeObject(colorArray, forKey: "colors")
    }