 import UIKit
 import HKLColorTable
 
-private let items: [String] = [
-    "JIS Colors", "Japanese traditional colors", "Common colors", "Web color", "PANTONE"
-]
+private enum Colors: String {
+    case JIS = "JIS Colors"
+    case JapanTraditional = "Traditional Japanese colors"
+    case Common = "Common colors"
+    case Web = "Web color"
+    case PANTONE = "PANTONE"
 
-private func numColors(colors: String) -> Int {
-    switch colors {
-    case "JIS Colors":
-        return JpnJISColor.Enji.count()
-    case "Japanese traditional colors":
-        return JpnColor.Enji.count()
-    case "Common colors":
-        return CommonColor.Amber.count()
-    case "Web color":
-        return WebColor.Aliceblue.count()
-    case "PANTONE":
-        return PantoneColor.No100.count()
-    default:
-        fatalError("Invalid color name")
-        break
+    var numColors: Int {
+        switch self {
+        case .JIS:
+            return JpnJISColor.Enji.count()
+        case .JapanTraditional:
+            return JpnColor.Enji.count()
+        case .Common:
+            return CommonColor.Amber.count()
+        case .Web:
+            return WebColor.Aliceblue.count()
+        case .PANTONE:
+            return PantoneColor.No100.count()
+        }
+    }
+
+    var colorArray: [HKLColorTableRepresentable] {
+
+        let f: (Int) -> HKLColorTableRepresentable
+        switch self {
+        case .JIS:
+            f = { JpnJISColor(rawValue: $0)! }
+        case .JapanTraditional:
+            f = { JpnColor(rawValue: $0)! }
+        case .Common:
+            f = { CommonColor(rawValue: $0)! }
+        case .Web:
+            f = { WebColor(rawValue: $0)! }
+        case .PANTONE:
+            f = { PantoneColor(rawValue: $0)! }
+        }
+
+        var array = [HKLColorTableRepresentable]()
+        for i in 0..<numColors {
+            array.append(f(i))
+        }
+        return array
     }
 }
 
-private func colorArray(colors: String) -> [HKLColorTableRepresentable] {
-    let count = numColors(colors)
-
-    let f: (Int) -> HKLColorTableRepresentable
-
-    switch colors {
-    case "JIS Colors":
-        f = { JpnJISColor(rawValue: $0)! }
-    case "Japanese traditional colors":
-        f = { JpnColor(rawValue: $0)! }
-    case "Common colors":
-        f = { CommonColor(rawValue: $0)! }
-    case "Web color":
-        f = { WebColor(rawValue: $0)! }
-    case "PANTONE":
-        f = { PantoneColor(rawValue: $0)! }
-    default:
-        fatalError("Invalid color name")
-        break
-    }
-
-    var array = [HKLColorTableRepresentable]()
-    for i in 0..<count {
-        array.append(f(i))
-    }
-    return array
-}
+private let items: [Colors] = [
+    .JIS, .JapanTraditional, .Common, .Web, .PANTONE
+]
 
 class RootViewController: UITableViewController {
 

        switch segue.identifier! {
        case "ToDetail":
            if let nextVc = segue.destinationViewController as? ColorListViewController {
                let title = items[tableView.indexPathForSelectedRow!.row]
                nextVc.title = title
                nextVc.colors = colorArray(title)
            }
        default:
            break

    }
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("Category", forIndexPath: indexPath)
        cell.textLabel?.text = items[indexPath.row].rawValue
        cell.detailTextLabel?.text = "\(items[indexPath.row].numColors))"
        print(cell.detailTextLabel?.text)
        return cell
    }
