                 else
                 { // all others
                     
-                    for (var j = 0; j < clrs.count && j < entryCount; j++)
+                    for j in 0..<min(clrs.count, entryCount)
                     {
                         // if multiple colors are set for a DataSet, group them
                         if (j < clrs.count - 1 && j < entryCount - 1)

                    let bds = dataSet as! BarChartDataSet
                    var sLabels = bds.stackLabels
                    
                    for (var j = 0; j < clrs.count && j < bds.stackSize; j++)
                    {
                        labels.append(sLabels[j % sLabels.count])
                        colors.append(clrs[j])

                }
            }
            
            for i in 0..<labels.count
            {
                let drawingForm = colors[i] != nil
                var x = posX
