         var enumerator = leftEdgeColors.objectEnumerator()
         var sortedColors = NSMutableArray(capacity: leftEdgeColors.count)
         while let kolor = enumerator.nextObject() as? UIColor {
-            let colorCount = leftEdgeColors.countForObject(kolor)
+            let colorCount = leftEdgeColors.count(for: kolor)
             if randomColorsThreshold < colorCount  {
-                sortedColors.addObject(PCCountedColor(color: kolor, count: colorCount))
-            }
-        }
-        sortedColors.sortUsingComparator(sortedColorComparator)
+                sortedColors.add(PCCountedColor(color: kolor, count: colorCount))
+            }
+        }
+        sortedColors.sort(comparator: sortedColorComparator)
         
         var proposedEdgeColor: PCCountedColor
         if 0 < sortedColors.count {
-            proposedEdgeColor = sortedColors.objectAtIndex(0) as! PCCountedColor
+            proposedEdgeColor = sortedColors.object(at: 0) as! PCCountedColor
         } else {
             proposedEdgeColor = PCCountedColor(color: blackColor, count: 1)
         }
         
         if proposedEdgeColor.color.isBlackOrWhite && 0 < sortedColors.count {
             for i in 1..<sortedColors.count {
-                let nextProposedEdgeColor = sortedColors.objectAtIndex(i) as! PCCountedColor
+                let nextProposedEdgeColor = sortedColors.object(at: i) as! PCCountedColor
                 if (CGFloat(nextProposedEdgeColor.count)/CGFloat(proposedEdgeColor.count)) > 0.3 {
                     if !nextProposedEdgeColor.color.isBlackOrWhite {
                         proposedEdgeColor = nextProposedEdgeColor

        let findDarkTextColor = !result.backgroundColor.isDarkColor
        
        while var kolor = enumerator.nextObject() as? UIColor {
            kolor = kolor.colorWithMinimumSaturation(0.15)
            if kolor.isDarkColor == findDarkTextColor {
                let colorCount = imageColors.countForObject(kolor)
                sortedColors.addObject(PCCountedColor(color: kolor, count: colorCount))
            }
        }
        sortedColors.sortUsingComparator(sortedColorComparator)
        
        for curContainer in sortedColors {
            let kolor = (curContainer as! PCCountedColor).color
            
            if result.primaryColor == nil {
                if kolor.isContrastingColor(result.backgroundColor) {
                    result.primaryColor = kolor
                }
            } else if result.secondaryColor == nil {
                if !result.primaryColor.isDistinct(kolor) || !kolor.isContrastingColor(result.backgroundColor) {
                    continue
                }
                
                result.secondaryColor = kolor
            } else if result.detailColor == nil {
                if !result.secondaryColor.isDistinct(kolor) || !result.primaryColor.isDistinct(kolor) || !kolor.isContrastingColor(result.backgroundColor) {
                    continue
                }
                

    public func getColors(scaleDownSize: CGSize = CGSize.zero) -> UIImageColors {
        
        var scaleDownSize = scaleDownSize
        
        if scaleDownSize == CGSize.zero {
            let ratio = self.size.width/self.size.height
            let r_width: CGFloat = 250
            scaleDownSize = CGSize(width: r_width, height: r_width/ratio)
        }
        
        var result = UIImageColors()
        
        let cgImage = self.resizeForUIImageColors(newSize: scaleDownSize).cgImage!
        let width = cgImage.width
        let height = cgImage.height
        
        let bytesPerPixel: Int = 4
        let bytesPerRow: Int = width * bytesPerPixel
        let bitsPerComponent: Int = 8
        let randomColorsThreshold = Int(CGFloat(height)*0.01)
        let sortedColorComparator: Comparator = { (main, other) -> ComparisonResult in
            let m = main as! PCCountedColor, o = other as! PCCountedColor
            if m.count < o.count {
                return ComparisonResult.orderedDescending
            } else if m.count == o.count {
                return ComparisonResult.orderedSame
            } else {
                return ComparisonResult.orderedAscending
            }
        }
        let blackColor = UIColor(red: 0, green: 0, blue: 0, alpha: 1)
