OSDN Git Service

CollectionViewの実装から具体的なクラス名を排除
[kcd/KCD.git] / KCD / MainTabVIewItemViewController.swift
index cc6e516..ffdb005 100644 (file)
@@ -9,7 +9,8 @@
 import Cocoa
 
 @objc
-enum ShipType: Int {
+enum ShipTabType: Int {
+    
     case all = 0
     case destroyer = 1
     case lightCruiser = 2
@@ -21,6 +22,7 @@ enum ShipType: Int {
 }
 
 class MainTabVIewItemViewController: NSViewController {
+    
     let shipTypeCategories: [[Int]] = [
         [0],    // dummy
         [2],    // destoryer
@@ -32,22 +34,26 @@ class MainTabVIewItemViewController: NSViewController {
         [1, 15, 17, 19, 20, 21, 22]
     ]
     
-    dynamic var hasShipTypeSelector: Bool { return false }
-    dynamic var selectedShipType: ShipType = .all
+    @objc dynamic var hasShipTypeSelector: Bool { return false }
+    @objc dynamic var selectedShipType: ShipTabType = .all
     
     var shipTypePredicte: NSPredicate? {
+        
         switch selectedShipType {
         case .all:
             return nil
+            
         case .destroyer, .lightCruiser, .heavyCruiser,
              .aircraftCarrier, .battleShip, .submarine:
-            return NSPredicate(format: "master_ship.stype.id IN %@", shipTypeCategories[selectedShipType.rawValue])
+            return NSPredicate(#keyPath(Ship.master_ship.stype.id), valuesIn: shipTypeCategories[selectedShipType.rawValue])
+            
         case .other:
             let omitTypes = shipTypeCategories
+                .lazy
                 .enumerated()
                 .filter { $0.offset != 0 && $0.offset != 7 }
                 .flatMap { $0.element }
-            return NSPredicate(format: "NOT master_ship.stype.id IN %@", omitTypes)
+            return .not(NSPredicate(#keyPath(Ship.master_ship.stype.id), valuesIn: omitTypes))
         }
     }
 }