             alpha: CGFloat(1.0)
         )
     }
-
-    // slightly darkened colors
-
-
-    func colorByDarkeningWithValue(value: CGFloat) -> UIColor {
-
-        let numberOfComponenets = CGColorGetNumberOfComponents(self.CGColor)
-        let isGreyscale = numberOfComponenets == 2
-
-        let oldComponents = CGColorGetComponents(self.CGColor)
-        var newComponents: [CGFloat] = [0.0, 0.0, 0.0, 0.0]
-
-        if isGreyscale {
-            newComponents[0] = oldComponents[0] - value < 0.0 ? 0.0 : oldComponents[0] - value
-            newComponents[1] = oldComponents[0] - value < 0.0 ? 0.0 : oldComponents[0] - value
-            newComponents[2] = oldComponents[0] - value < 0.0 ? 0.0 : oldComponents[0] - value
-            newComponents[3] = oldComponents[1];
-        } else {
-            newComponents[0] = oldComponents[0] - value < 0.0 ? 0.0 : oldComponents[0] - value
-            newComponents[1] = oldComponents[1] - value < 0.0 ? 0.0 : oldComponents[1] - value
-            newComponents[2] = oldComponents[2] - value < 0.0 ? 0.0 : oldComponents[2] - value
-            newComponents[3] = oldComponents[3]
-        }
-
-        let colorSpace = CGColorSpaceCreateDeviceRGB()
-        let newColor = CGColorCreate(colorSpace, newComponents)
-
-        return UIColor(CGColor: newColor!)
-    }
 }
 
 


    func addCenterYConstraintsToView(view: UIView, offset: CGFloat) {
        self.addConstraint(NSLayoutConstraint(item: self, attribute: .CenterY, relatedBy: .Equal, toItem: view, attribute: .CenterY, multiplier: 1.0, constant: -offset))
    }

    // Height and Width

            return theResult
        } else {
            return nil
        }
    }
}

extension Array {

    mutating func appendAsQueueWithLength(newElement: Element, length: Int) {
        if self.count < length {
            self.append(newElement)
        } else {
            self.removeFirst()
            self.append(newElement)
        }
        assert(self.count <= length)
    }
}

// Calculates the average value of all elements in array
extension _ArrayType where Generator.Element == Double {

    func getAverage() -> Double {
        var average: Double = 0.0
        self.forEach({average += $0})
        return average / Double(self.count)
    }
}

extension CLLocationManager {
    func enableBackgroundLocation() {
        if #available(iOS 9.0, *) {
            self.allowsBackgroundLocationUpdates = true
        } else {
            // background location enabled by default
        }
    }
}

extension UITextField {

    func applyAttributedPlaceHolderForTextField() {
        let attributedPlaceholder = NSMutableAttributedString()
        let attributedText = NSMutableAttributedString(string: self.placeholder ?? "", attributes: [NSForegroundColorAttributeName : UIColor.lightGrayColor()])
        attributedPlaceholder.appendAttributedString(attributedText)
        self.attributedPlaceholder = attributedPlaceholder
    }
}

// Extension to get last n elements of array
extension CollectionType {
    func last(count:Int) -> [Self.Generator.Element] {
        let selfCount = self.count as! Int
        if selfCount <= count - 1 {
            return Array(self)
        } else {
            return Array(self.reverse()[0...count - 1].reverse())
        }
    }
}
