OSDN Git Service

#keyPathが使用可能な部分にそれを適用
authormasakih <masakih@users.sourceforge.jp>
Fri, 6 Oct 2017 13:10:59 +0000 (22:10 +0900)
committermasakih <masakih@users.sourceforge.jp>
Fri, 6 Oct 2017 13:10:59 +0000 (22:10 +0900)
KCD/BookmarkManager.swift
KCD/CombileViewController.swift
KCD/Deck.swift
KCD/DestroyItem2Command.swift
KCD/FleetViewController.swift
KCD/MaterialMapper.swift
KCD/QuestListViewController.swift
KCD/ServerDataStore.swift
KCD/ShipDetailViewController.swift
KCD/ShipViewController.swift
KCD/TemporaryDataStore.swift

index 6b3e4fa..319b83c 100644 (file)
@@ -35,7 +35,7 @@ final class BookmarkManager: NSObject, NSMenuDelegate {
         
         bookmarksController.managedObjectContext = self.manageObjectContext
         bookmarksController.entityName = Bookmark.entityName
-        let sort = NSSortDescriptor(key: "order", ascending: true)
+        let sort = NSSortDescriptor(key: #keyPath(Bookmark.order), ascending: true)
         bookmarksController.sortDescriptors = [sort]
         
         let mainMenu = NSApplication.shared.mainMenu
index 9786332..003724f 100644 (file)
@@ -94,14 +94,14 @@ final class CombileViewController: NSViewController {
             $0.element.1.fleetNumber = $0.offset + 1
         }
         
-        bind(NSBindingName(#keyPath(fleet1TPValue)), to: fleet1, withKeyPath: "totalTPValue")
-        bind(NSBindingName(#keyPath(fleet2TPValue)), to: fleet2, withKeyPath: "totalTPValue")
+        bind(NSBindingName(#keyPath(fleet1TPValue)), to: fleet1, withKeyPath: #keyPath(FleetViewController.totalTPValue))
+        bind(NSBindingName(#keyPath(fleet2TPValue)), to: fleet2, withKeyPath: #keyPath(FleetViewController.totalTPValue))
         
-        bind(NSBindingName(#keyPath(fleet1Seiku)), to: fleet1, withKeyPath: "totalSeiku")
-        bind(NSBindingName(#keyPath(fleet2Seiku)), to: fleet2, withKeyPath: "totalSeiku")
+        bind(NSBindingName(#keyPath(fleet1Seiku)), to: fleet1, withKeyPath: #keyPath(FleetViewController.totalSeiku))
+        bind(NSBindingName(#keyPath(fleet2Seiku)), to: fleet2, withKeyPath: #keyPath(FleetViewController.totalSeiku))
         
-        bind(NSBindingName(#keyPath(fleet1CalculatedSeiku)), to: fleet1, withKeyPath: "totalCalclatedSeiku")
-        bind(NSBindingName(#keyPath(fleet2CalculatedSeiku)), to: fleet2, withKeyPath: "totalCalclatedSeiku")
+        bind(NSBindingName(#keyPath(fleet1CalculatedSeiku)), to: fleet1, withKeyPath: #keyPath(FleetViewController.totalCalclatedSeiku))
+        bind(NSBindingName(#keyPath(fleet2CalculatedSeiku)), to: fleet2, withKeyPath: #keyPath(FleetViewController.totalCalclatedSeiku))
     }
     
     deinit {
index f6bbc0c..2e58771 100644 (file)
@@ -61,7 +61,7 @@ extension Deck {
         
         guard let moc = self.managedObjectContext else { return nil }
         
-        let req = NSFetchRequest<Ship>(entityName: "Ship")
+        let req = NSFetchRequest<Ship>(entityName: Ship.entityName)
         req.predicate = NSPredicate(format: "id = %ld", identifier)
         
         guard let ships = try? moc.fetch(req) else { return nil }
index d3e5f53..4664c7b 100644 (file)
@@ -43,7 +43,7 @@ final class DestroyItem2Command: JSONCommand {
             return
         }
         
-        let resouces = ["fuel", "bull", "steel", "bauxite"]
+        let resouces = [#keyPath(Material.fuel), #keyPath(Material.bull), #keyPath(Material.steel), #keyPath(Material.bauxite)]
         
         zip(gm, resouces).forEach {
             
index 36d8f08..017629b 100644 (file)
@@ -50,10 +50,10 @@ final class FleetViewController: NSViewController {
     private static let maxFleetNumber: Int = 4
     
     private let details: [ShipDetailViewController]
-    private let shipKeys = ["ship_0", "ship_1", "ship_2", "ship_3", "ship_4", "ship_5"]
+    private let shipKeys = [#keyPath(Deck.ship_0), #keyPath(Deck.ship_1), #keyPath(Deck.ship_2), #keyPath(Deck.ship_3), #keyPath(Deck.ship_4), #keyPath(Deck.ship_5)]
     private let type: FleetViewType
     private let fleetController = NSObjectController()
-    private let shipObserveKeys = ["seiku", "lv", "equippedItem"]
+    private let shipObserveKeys = [#keyPath(Ship.seiku), #keyPath(Ship.lv), #keyPath(Ship.equippedItem)]
     
     init?(viewType: FleetViewType) {
         
@@ -235,7 +235,7 @@ final class FleetViewController: NSViewController {
             sakutekiCalculator = Formula33(Int(factor))
         }
         
-        fleetController.bind(NSBindingName("content"), to:self, withKeyPath:#keyPath(fleet), options:nil)
+        fleetController.bind(NSBindingName(#keyPath(NSArrayController.content)), to:self, withKeyPath:#keyPath(fleet), options:nil)
         fleetController.addObserver(self, forKeyPath:"selection.name", context:nil)
         shipKeys.forEach {
             
@@ -303,17 +303,17 @@ final class FleetViewController: NSViewController {
             if context == &shipsContext {
                 
                 switch keyPath {
-                case "equippedItem":
+                case #keyPath(Ship.equippedItem):
                     notifyChangeValue(forKey: #keyPath(totalSakuteki))
                     notifyChangeValue(forKey: #keyPath(totalDrums))
                     notifyChangeValue(forKey: #keyPath(totalCalclatedSeiku))
                     notifyChangeValue(forKey: #keyPath(totalTPValue))
                     
-                case "seiku":
+                case #keyPath(Ship.seiku):
                     notifyChangeValue(forKey: #keyPath(totalSeiku))
                     notifyChangeValue(forKey: #keyPath(totalCalclatedSeiku))
                     
-                case "lv":
+                case #keyPath(Ship.lv):
                     notifyChangeValue(forKey: #keyPath(totalLevel))
                     
                 default: break
index 678e80c..db400ae 100644 (file)
@@ -15,8 +15,8 @@ final class MaterialMapper: JSONMapper {
     let configuration: MappingConfiguration<Material>
     
     private let keys = [
-        "fuel", "bull", "steel", "bauxite",
-        "kousokukenzo", "kousokushuhuku", "kaihatusizai", "screw"
+        #keyPath(Material.fuel), #keyPath(Material.bull), #keyPath(Material.steel), #keyPath(Material.bauxite),
+        #keyPath(Material.kousokukenzo), #keyPath(Material.kousokushuhuku), #keyPath(Material.kaihatusizai), #keyPath(Material.screw)
     ]
     
     required init(_ apiResponse: APIResponse) {
index 621ea5b..2cf0266 100644 (file)
@@ -11,7 +11,7 @@ import Cocoa
 final class QuestListViewController: NSViewController {
     
     @objc let managedObjectContext = ServerDataStore.default.context
-    @objc let sortDesciptors = [NSSortDescriptor(key: "no", ascending: true)]
+    @objc let sortDesciptors = [NSSortDescriptor(key: #keyPath(Quest.no), ascending: true)]
     
     override var nibName: NSNib.Name {
         
index 82e2310..b299a4b 100644 (file)
@@ -133,7 +133,7 @@ extension ServerDataStore {
     
     func sortedMasterShipsById() -> [MasterShip] {
         
-        let sortDesc = NSSortDescriptor(key: "id", ascending: true)
+        let sortDesc = NSSortDescriptor(key: #keyPath(MasterShip.id), ascending: true)
         
         guard let ships = try? objects(of: MasterShip.entity, sortDescriptors: [sortDesc]) else { return [] }
         
@@ -151,7 +151,7 @@ extension ServerDataStore {
     
     func sortedMasterSlotItemsById() -> [MasterSlotItem] {
         
-        let sortDesc = NSSortDescriptor(key: "id", ascending: true)
+        let sortDesc = NSSortDescriptor(key: #keyPath(MasterSlotItem.id), ascending: true)
         
         guard let masterSlotItems = try? objects(of: MasterSlotItem.entity, sortDescriptors: [sortDesc]) else { return [] }
         
@@ -192,7 +192,7 @@ extension ServerDataStore {
     
     func sortedMasterSTypesById() -> [MasterSType] {
         
-        let sortDesc = NSSortDescriptor(key: "id", ascending: true)
+        let sortDesc = NSSortDescriptor(key: #keyPath(MasterSType.id), ascending: true)
         
         guard let masterSTypes = try? objects(of: MasterSType.entity, sortDescriptors: [sortDesc]) else { return [] }
         
@@ -296,7 +296,7 @@ extension ServerDataStore {
     
     func sortedSlotItemsById() -> [SlotItem] {
         
-        let sortDesc = NSSortDescriptor(key: "id", ascending: true)
+        let sortDesc = NSSortDescriptor(key: #keyPath(SlotItem.id), ascending: true)
         
         guard let slotItems = try? objects(of: SlotItem.entity, sortDescriptors: [sortDesc]) else { return [] }
         
@@ -342,7 +342,7 @@ extension ServerDataStore {
     
     func quest(by no: Int) -> Quest? {
         
-        let p = NSPredicate(format: "%K = %ld", "no", no)
+        let p = NSPredicate(format: "%K = %ld", #keyPath(Quest.no), no)
         
         guard let quests = try? objects(of: Quest.entity, predicate: p) else { return nil }
         
@@ -351,7 +351,7 @@ extension ServerDataStore {
     
     func quests(in range: CountableClosedRange<Int>) -> [Quest] {
         
-        let p = NSPredicate(format: "%K In %@", "no", range.map {$0})
+        let p = NSPredicate(format: "%K In %@", #keyPath(Quest.no), range.map {$0})
         
         guard let quests = try? objects(of: Quest.entity, predicate: p) else { return [] }
         
@@ -360,7 +360,7 @@ extension ServerDataStore {
     
     func sortedQuestByNo() -> [Quest] {
         
-        let sortDesc = NSSortDescriptor(key: "no", ascending: true)
+        let sortDesc = NSSortDescriptor(key: #keyPath(Quest.no), ascending: true)
         
         guard let quests = try? objects(of: Quest.entity, sortDescriptors: [sortDesc]) else { return [] }
         
index b67473b..331f5b8 100644 (file)
@@ -153,51 +153,51 @@ final class ShipDetailViewController: NSViewController {
         
         if context == &shipContext {
             
-            notifyChangeValue(forKey: "planeString0")
-            notifyChangeValue(forKey: "planeString0Color")
-            notifyChangeValue(forKey: "planeString1")
-            notifyChangeValue(forKey: "planeString1Color")
-            notifyChangeValue(forKey: "planeString2")
-            notifyChangeValue(forKey: "planeString2Color")
-            notifyChangeValue(forKey: "planeString3")
-            notifyChangeValue(forKey: "planeString3Color")
-            notifyChangeValue(forKey: "planeString4")
-            notifyChangeValue(forKey: "planeString4Color")
+            notifyChangeValue(forKey: #keyPath(planeString0))
+            notifyChangeValue(forKey: #keyPath(planeString0Color))
+            notifyChangeValue(forKey: #keyPath(planeString1))
+            notifyChangeValue(forKey: #keyPath(planeString1Color))
+            notifyChangeValue(forKey: #keyPath(planeString2))
+            notifyChangeValue(forKey: #keyPath(planeString2Color))
+            notifyChangeValue(forKey: #keyPath(planeString3))
+            notifyChangeValue(forKey: #keyPath(planeString3Color))
+            notifyChangeValue(forKey: #keyPath(planeString4))
+            notifyChangeValue(forKey: #keyPath(planeString4Color))
             
             return
         }
         if context == &equippedItem0Context {
             
-            notifyChangeValue(forKey: "planeString0")
-            notifyChangeValue(forKey: "planeString0Color")
+            notifyChangeValue(forKey: #keyPath(planeString0))
+            notifyChangeValue(forKey: #keyPath(planeString0Color))
             
             return
         }
         if context == &equippedItem1Context {
             
-            notifyChangeValue(forKey: "planeString1")
-            notifyChangeValue(forKey: "planeString1Color")
+            notifyChangeValue(forKey: #keyPath(planeString1))
+            notifyChangeValue(forKey: #keyPath(planeString1Color))
             
             return
         }
         if context == &equippedItem2Context {
             
-            notifyChangeValue(forKey: "planeString2")
-            notifyChangeValue(forKey: "planeString2Color")
+            notifyChangeValue(forKey: #keyPath(planeString2))
+            notifyChangeValue(forKey: #keyPath(planeString2Color))
             
             return
         }
         if context == &equippedItem3Context {
             
-            notifyChangeValue(forKey: "planeString3")
-            notifyChangeValue(forKey: "planeString3Color")
+            notifyChangeValue(forKey: #keyPath(planeString3))
+            notifyChangeValue(forKey: #keyPath(planeString3Color))
             
             return
         }
         if context == &equippedItem4Context {
             
-            notifyChangeValue(forKey: "planeString4")
-            notifyChangeValue(forKey: "planeString4Color")
+            notifyChangeValue(forKey: #keyPath(planeString4))
+            notifyChangeValue(forKey: #keyPath(planeString4Color))
             
             return
         }
index 1031ab8..4d7b96e 100644 (file)
@@ -81,7 +81,7 @@ final class ShipViewController: MainTabVIewItemViewController {
         
         shipController.sortDescriptors = UserDefaults.standard[.shipviewSortDescriptors]
         shipController.addObserver(self, forKeyPath: NSBindingName.sortDescriptors.rawValue, context: nil)
-        shipController.addObserver(self, forKeyPath: "arrangedObjects", context: nil)
+        shipController.addObserver(self, forKeyPath: #keyPath(NSArrayController.arrangedObjects), context: nil)
         
         let tableViews = [expTableView, powerTableView, power2TableView, power3TableView]
         tableViews
@@ -112,9 +112,9 @@ final class ShipViewController: MainTabVIewItemViewController {
             return
         }
         
-        if keyPath == "arrangedObjects" {
+        if keyPath == #keyPath(NSArrayController.arrangedObjects) {
             
-            notifyChangeValue(forKey: "standardDeviation")
+            notifyChangeValue(forKey: #keyPath(standardDeviation))
             
             return
         }
index 1ffd6bd..303fa56 100644 (file)
@@ -67,7 +67,7 @@ extension TemporaryDataStore {
     
     func sortedDamagesById() -> [Damage] {
         
-        let sortDescriptor = NSSortDescriptor(key: "id", ascending: true)
+        let sortDescriptor = NSSortDescriptor(key: #keyPath(Damage.id), ascending: true)
         
         guard let damages = try? objects(of: Damage.entity, sortDescriptors: [sortDescriptor]) else { return [] }