From 308d3cce2d65aa4913aff66a7a51d368b2086dcf Mon Sep 17 00:00:00 2001 From: masakih Date: Fri, 6 Oct 2017 22:10:59 +0900 Subject: [PATCH] =?utf8?q?#keyPath=E3=81=8C=E4=BD=BF=E7=94=A8=E5=8F=AF?= =?utf8?q?=E8=83=BD=E3=81=AA=E9=83=A8=E5=88=86=E3=81=AB=E3=81=9D=E3=82=8C?= =?utf8?q?=E3=82=92=E9=81=A9=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- KCD/BookmarkManager.swift | 2 +- KCD/CombileViewController.swift | 12 ++++++------ KCD/Deck.swift | 2 +- KCD/DestroyItem2Command.swift | 2 +- KCD/FleetViewController.swift | 12 ++++++------ KCD/MaterialMapper.swift | 4 ++-- KCD/QuestListViewController.swift | 2 +- KCD/ServerDataStore.swift | 14 ++++++------- KCD/ShipDetailViewController.swift | 40 +++++++++++++++++++------------------- KCD/ShipViewController.swift | 6 +++--- KCD/TemporaryDataStore.swift | 2 +- 11 files changed, 49 insertions(+), 49 deletions(-) diff --git a/KCD/BookmarkManager.swift b/KCD/BookmarkManager.swift index 6b3e4fab..319b83c5 100644 --- a/KCD/BookmarkManager.swift +++ b/KCD/BookmarkManager.swift @@ -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 diff --git a/KCD/CombileViewController.swift b/KCD/CombileViewController.swift index 97863323..003724ff 100644 --- a/KCD/CombileViewController.swift +++ b/KCD/CombileViewController.swift @@ -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 { diff --git a/KCD/Deck.swift b/KCD/Deck.swift index f6bbc0ce..2e58771c 100644 --- a/KCD/Deck.swift +++ b/KCD/Deck.swift @@ -61,7 +61,7 @@ extension Deck { guard let moc = self.managedObjectContext else { return nil } - let req = NSFetchRequest(entityName: "Ship") + let req = NSFetchRequest(entityName: Ship.entityName) req.predicate = NSPredicate(format: "id = %ld", identifier) guard let ships = try? moc.fetch(req) else { return nil } diff --git a/KCD/DestroyItem2Command.swift b/KCD/DestroyItem2Command.swift index d3e5f53c..4664c7b7 100644 --- a/KCD/DestroyItem2Command.swift +++ b/KCD/DestroyItem2Command.swift @@ -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 { diff --git a/KCD/FleetViewController.swift b/KCD/FleetViewController.swift index 36d8f085..017629be 100644 --- a/KCD/FleetViewController.swift +++ b/KCD/FleetViewController.swift @@ -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 diff --git a/KCD/MaterialMapper.swift b/KCD/MaterialMapper.swift index 678e80c9..db400aef 100644 --- a/KCD/MaterialMapper.swift +++ b/KCD/MaterialMapper.swift @@ -15,8 +15,8 @@ final class MaterialMapper: JSONMapper { let configuration: MappingConfiguration 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) { diff --git a/KCD/QuestListViewController.swift b/KCD/QuestListViewController.swift index 621ea5b2..2cf02663 100644 --- a/KCD/QuestListViewController.swift +++ b/KCD/QuestListViewController.swift @@ -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 { diff --git a/KCD/ServerDataStore.swift b/KCD/ServerDataStore.swift index 82e2310e..b299a4b3 100644 --- a/KCD/ServerDataStore.swift +++ b/KCD/ServerDataStore.swift @@ -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) -> [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 [] } diff --git a/KCD/ShipDetailViewController.swift b/KCD/ShipDetailViewController.swift index b67473b3..331f5b8b 100644 --- a/KCD/ShipDetailViewController.swift +++ b/KCD/ShipDetailViewController.swift @@ -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 } diff --git a/KCD/ShipViewController.swift b/KCD/ShipViewController.swift index 1031ab8c..4d7b96e4 100644 --- a/KCD/ShipViewController.swift +++ b/KCD/ShipViewController.swift @@ -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 } diff --git a/KCD/TemporaryDataStore.swift b/KCD/TemporaryDataStore.swift index 1ffd6bdf..303fa56d 100644 --- a/KCD/TemporaryDataStore.swift +++ b/KCD/TemporaryDataStore.swift @@ -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 [] } -- 2.11.0