OSDN Git Service

MappingConfigurationのプロパティを変更
authormasakih <masakih@users.sourceforge.jp>
Sun, 19 Mar 2017 04:05:48 +0000 (13:05 +0900)
committermasakih <masakih@users.sourceforge.jp>
Sun, 19 Mar 2017 04:05:48 +0000 (13:05 +0900)
SwifttyJSONに最適化するため let dataKey: Stringを let dataKeys: [String]に変更

18 files changed:
KCD/AirBaseMapper.swift
KCD/BasicMapper.swift
KCD/DeckMapper.swift
KCD/JSONMapper.swift
KCD/KenzoDockMapper.swift
KCD/MasterFurnitureMapper.swift
KCD/MasterMapAreaMapper.swift
KCD/MasterMapInfoMapper.swift
KCD/MasterMissionMapper.swift
KCD/MasterSTypeMapper.swift
KCD/MasterShipMapper.swift
KCD/MasterSlotItemEquipTypeMapper.swift
KCD/MasterSlotItemMapper.swift
KCD/MasterUseItemMapper.swift
KCD/MaterialMapper.swift
KCD/NyukyoDockMapper.swift
KCD/ShipMapper.swift
KCD/SlotItemMapper.swift

index 02e1d5f..c429924 100644 (file)
@@ -14,7 +14,7 @@ class AirBaseMapper: JSONMapper {
     
     let apiResponse: APIResponse
     let configuration = MappingConfiguration(entity: AirBase.entity,
-                                             dataKey: "api_data.api_air_base",
+                                             dataKeys: ["api_data", "api_air_base"],
                                              compositPrimaryKeys: ["area_id", "rid"],
                                              editorStore: ServerDataStore.oneTimeEditor())
     
index 199746a..83780b1 100644 (file)
@@ -13,12 +13,12 @@ fileprivate enum BasicAPI: String {
     case port = "/kcsapi/api_port/port"
 }
 
-fileprivate func dataKey(_ apiResponse: APIResponse) -> String {
+fileprivate func dataKeys(_ apiResponse: APIResponse) -> [String] {
     guard let basicApi = BasicAPI(rawValue: apiResponse.api)
-        else { return "api_data" }
+        else { return ["api_data"] }
     switch basicApi {
-    case .port: return "api_data.api_basic"
-    default: return "api_data"
+    case .port: return ["api_data", "api_basic"]
+    default: return ["api_data"]
     }
 }
 
@@ -31,7 +31,7 @@ class BasicMapper: JSONMapper {
     required init(_ apiResponse: APIResponse) {
         self.apiResponse = apiResponse
         self.configuration = MappingConfiguration(entity: Basic.entity,
-                                                  dataKey: dataKey(apiResponse),
+                                                  dataKeys: dataKeys(apiResponse),
                                                   editorStore: ServerDataStore.oneTimeEditor())
     }
     
index d4bb9a2..78216e5 100644 (file)
@@ -19,16 +19,16 @@ fileprivate enum DeckAPI: String {
     case kaisouPowerUp = "/kcsapi/api_req_kaisou/powerup"
 }
 
-fileprivate func dataKey(_ apiResponse: APIResponse) -> String {
+fileprivate func dataKeys(_ apiResponse: APIResponse) -> [String] {
     guard let deckApi = DeckAPI(rawValue: apiResponse.api)
-        else { return "api_data" }
+        else { return ["api_data"] }
     switch deckApi {
-    case .port: return "api_data.api_deck_port"
-    case .getMemberShip2: return "api_data_deck"
-    case .getMemberShip3: return "api_data.api_deck_data"
-    case .getMemberShipDeck: return "api_data.api_deck_data"
-    case .kaisouPowerUp: return "api_data.api_deck"
-    default: return "api_data"
+    case .port: return ["api_data", "api_deck_port"]
+    case .getMemberShip2: return ["api_data_deck"]
+    case .getMemberShip3: return ["api_data", "api_deck_data"]
+    case .getMemberShipDeck: return ["api_data", "api_deck_data"]
+    case .kaisouPowerUp: return ["api_data", "api_deck"]
+    default: return ["api_data"]
     }
 }
 
@@ -41,7 +41,7 @@ class DeckMapper: JSONMapper {
     required init(_ apiResponse: APIResponse) {
         self.apiResponse = apiResponse
         self.configuration = MappingConfiguration(entity: Deck.entity,
-                                                  dataKey: dataKey(apiResponse),
+                                                  dataKeys: dataKeys(apiResponse),
                                                   editorStore: ServerDataStore.oneTimeEditor())
     }
 }
index 54055e4..b19fa1f 100644 (file)
@@ -11,20 +11,20 @@ import SwiftyJSON
 
 struct MappingConfiguration<T: NSManagedObject> {
     let entity: Entity<T>
-    let dataKey: String
+    let dataKeys: [String]
     let primaryKey: String
     let compositPrimaryKeys: [String]?
     let editorStore: CoreDataAccessor
     let ignoreKeys: [String]
     
     init(entity: Entity<T>,
-         dataKey: String = "api_data",
+         dataKeys: [String] = ["api_data"],
          primaryKey: String = "id",
          compositPrimaryKeys: [String]? = nil,
          editorStore: CoreDataAccessor,
          ignoreKeys: [String] = []) {
         self.entity = entity
-        self.dataKey = dataKey
+        self.dataKeys = dataKeys
         self.primaryKey = primaryKey
         self.compositPrimaryKeys = compositPrimaryKeys
         self.editorStore = editorStore
@@ -56,7 +56,7 @@ extension String {
 }
 
 extension JSONMapper {
-    var data: JSON { return apiResponse.json.value(for: configuration.dataKey) }
+    var data: JSON { return apiResponse.json[configuration.dataKeys] }
     
     private func isEqual(_ lhs: AnyObject?, _ rhs: AnyObject?) -> Bool {
         if lhs == nil, rhs == nil { return true }
index 106504a..55e08ca 100644 (file)
@@ -14,13 +14,13 @@ fileprivate enum KenzoDockAPI: String {
     case getMemberRequireInfo = "/kcsapi/api_get_member/require_info"
 }
 
-fileprivate func dataKey(_ apiResponse: APIResponse) -> String {
+fileprivate func dataKeys(_ apiResponse: APIResponse) -> [String] {
     guard let kenzoDockApi = KenzoDockAPI(rawValue: apiResponse.api)
-        else { return "api_data" }
+        else { return ["api_data"] }
     switch kenzoDockApi {
-    case .kousyouGetShip: return "api_data.api_kdock"
-    case .getMemberRequireInfo: return "api_data.api_kdock"
-    default: return "api_data"
+    case .kousyouGetShip: return ["api_data", "api_kdock"]
+    case .getMemberRequireInfo: return ["api_data", "api_kdock"]
+    default: return ["api_data"]
     }
 }
 
@@ -32,7 +32,7 @@ class KenzoDockMapper: JSONMapper {
     required init(_ apiResponse: APIResponse) {
         self.apiResponse = apiResponse
         self.configuration = MappingConfiguration(entity: KenzoDock.entity,
-                                                  dataKey: dataKey(apiResponse),
+                                                  dataKeys: dataKeys(apiResponse),
                                                   editorStore: ServerDataStore.oneTimeEditor())
     }
 }
index 2df11c0..3ec58a3 100644 (file)
@@ -13,7 +13,7 @@ class MasterFurnitureMapper: JSONMapper {
 
     let apiResponse: APIResponse
     let configuration = MappingConfiguration(entity: MasterFurniture.entity,
-                                             dataKey: "api_data.api_mst_furniture",
+                                             dataKeys: ["api_data", "api_mst_furniture"],
                                              editorStore: ServerDataStore.oneTimeEditor(),
                                              ignoreKeys: ["api_season"])
     
index 2a2d71e..faef531 100644 (file)
@@ -13,7 +13,7 @@ class MasterMapAreaMapper: JSONMapper {
     
     let apiResponse: APIResponse
     let configuration = MappingConfiguration(entity: MasterMapArea.entity,
-                                             dataKey: "api_data.api_mst_maparea",
+                                             dataKeys: ["api_data", "api_mst_maparea"],
                                              editorStore: ServerDataStore.oneTimeEditor())
     
     required init(_ apiResponse: APIResponse) {
index c7049d6..01709c7 100644 (file)
@@ -13,7 +13,7 @@ class MasterMapInfoMapper: JSONMapper {
     
     let apiResponse: APIResponse
     let configuration = MappingConfiguration(entity: MasterMapInfo.entity,
-                                             dataKey: "api_data.api_mst_mapinfo",
+                                             dataKeys: ["api_data", "api_mst_mapinfo"],
                                              editorStore: ServerDataStore.oneTimeEditor())
     
     required init(_ apiResponse: APIResponse) {
index 6c54358..5fba4e0 100644 (file)
@@ -13,7 +13,7 @@ class MasterMissionMapper: JSONMapper {
 
     let apiResponse: APIResponse
     let configuration = MappingConfiguration(entity: MasterMission.entity,
-                                             dataKey: "api_data.api_mst_mission",
+                                             dataKeys: ["api_data", "api_mst_mission"],
                                              editorStore: ServerDataStore.oneTimeEditor())
     
     required init(_ apiResponse: APIResponse) {
index d2559ae..e37b99a 100644 (file)
@@ -13,7 +13,7 @@ class MasterSTypeMapper: JSONMapper {
 
     let apiResponse: APIResponse
     let configuration = MappingConfiguration(entity: MasterSType.entity,
-                                             dataKey: "api_data.api_mst_stype",
+                                             dataKeys: ["api_data", "api_mst_stype"],
                                              editorStore: ServerDataStore.oneTimeEditor(),
                                              ignoreKeys: ["api_equip_type"])
     
index 1ea39c3..d2f23fb 100644 (file)
@@ -14,7 +14,7 @@ class MasterShipMapper: JSONMapper {
     
     let apiResponse: APIResponse
     let configuration = MappingConfiguration(entity: MasterShip.entity,
-                                             dataKey: "api_data.api_mst_ship",
+                                             dataKeys: ["api_data", "api_mst_ship"],
                                              editorStore: ServerDataStore.oneTimeEditor())
     
     required init(_ apiResponse: APIResponse) {
index d6cc849..f37a3f6 100644 (file)
@@ -13,7 +13,7 @@ class MasterSlotItemEquipTypeMapper: JSONMapper {
 
     let apiResponse: APIResponse
     let configuration = MappingConfiguration(entity: MasterSlotItemEquipType.entity,
-                                             dataKey: "api_data.api_mst_slotitem_equiptype",
+                                             dataKeys: ["api_data", "api_mst_slotitem_equiptype"],
                                              editorStore: ServerDataStore.oneTimeEditor())
     
     required init(_ apiResponse: APIResponse) {
index 3c3303a..288fb31 100644 (file)
@@ -13,7 +13,7 @@ class MasterSlotItemMapper: JSONMapper {
 
     let apiResponse: APIResponse
     let configuration = MappingConfiguration(entity: MasterSlotItem.entity,
-                                             dataKey: "api_data.api_mst_slotitem",
+                                             dataKeys: ["api_data", "api_mst_slotitem"],
                                              editorStore: ServerDataStore.oneTimeEditor(),
                                              ignoreKeys: ["api_version"])
     
index d98cfe7..a309bfb 100644 (file)
@@ -13,7 +13,7 @@ class MasterUseItemMapper: JSONMapper {
 
     let apiResponse: APIResponse
     let configuration = MappingConfiguration(entity: MasterUseItem.entity,
-                                             dataKey: "api_data.api_mst_useitem",
+                                             dataKeys: ["api_dat", "api_mst_useitem"],
                                              editorStore: ServerDataStore.oneTimeEditor())
     
     required init(_ apiResponse: APIResponse) {
index 7c0d22a..586115b 100644 (file)
@@ -17,15 +17,15 @@ fileprivate enum MaterialAPI: String {
     case hokyuCharge = "/kcsapi/api_req_hokyu/charge"
 }
 
-fileprivate func dataKey(_ apiResponse: APIResponse) -> String {
+fileprivate func dataKeys(_ apiResponse: APIResponse) -> [String] {
     guard let materialApi = MaterialAPI(rawValue: apiResponse.api)
-        else { return "api_data" }
+        else { return ["api_data"] }
     switch materialApi {
-    case .port: return "api_data.api_material"
-    case .kousyouCreateItem: return "api_data.api_material"
-    case .kousyouDestoroyShip: return "api_data.api_material"
-    case .kousyouRemodelSlot: return "api_data.api_after_material"
-    case .hokyuCharge: return "api_data.api_material"
+    case .port: return ["api_data", "api_material"]
+    case .kousyouCreateItem: return ["api_data", "api_material"]
+    case .kousyouDestoroyShip: return ["api_data", "api_material"]
+    case .kousyouRemodelSlot: return ["api_data", "api_after_material"]
+    case .hokyuCharge: return ["api_data", "api_material"]
     }
 }
 
@@ -43,7 +43,7 @@ class MaterialMapper: JSONMapper {
     required init(_ apiResponse: APIResponse) {
         self.apiResponse = apiResponse
         self.configuration = MappingConfiguration(entity: Material.entity,
-                                                  dataKey: dataKey(apiResponse),
+                                                  dataKeys: dataKeys(apiResponse),
                                                   editorStore: ServerDataStore.oneTimeEditor())
     }
     
index 2f1481c..304a0a3 100644 (file)
@@ -13,12 +13,12 @@ fileprivate enum DeckAPI: String {
     case port = "/kcsapi/api_port/port"
 }
 
-fileprivate func dataKey(_ apiResponse: APIResponse) -> String {
+fileprivate func dataKeys(_ apiResponse: APIResponse) -> [String] {
     guard let deckApi = DeckAPI(rawValue: apiResponse.api)
-        else { return "api_data" }
+        else { return ["api_data"] }
     switch deckApi {
-    case .port: return "api_data.api_ndock"
-    default: return "api_data"
+    case .port: return ["api_data", "api_ndock"]
+    default: return ["api_data"]
     }
 }
 
@@ -31,7 +31,7 @@ class NyukyoDockMapper: JSONMapper {
     required init(_ apiResponse: APIResponse) {
         self.apiResponse = apiResponse
         self.configuration = MappingConfiguration(entity: NyukyoDock.entity,
-                                                  dataKey: dataKey(apiResponse),
+                                                  dataKeys: dataKeys(apiResponse),
                                                   editorStore: ServerDataStore.oneTimeEditor())
     }
 }
index cb5f47e..b61732c 100644 (file)
@@ -19,24 +19,24 @@ fileprivate enum ShipAPI: String {
     case kaisouSlotDeprive = "/kcsapi/api_req_kaisou/slot_deprive"
 }
 
-fileprivate func dataKey(_ apiResponse: APIResponse) -> String {
+fileprivate func dataKeys(_ apiResponse: APIResponse) -> [String] {
     guard let shipApi = ShipAPI(rawValue: apiResponse.api)
-        else { return "api_data" }
+        else { return ["api_data"] }
     switch shipApi {
-    case .port: return "api_data.api_ship"
-    case .getMemberShip3: return "api_data.api_ship_data"
-    case .kousyouGetShip: return "api_data.api_ship"
-    case .getMemberShipDeck: return "api_data.api_ship_data"
-    case .kaisouPowerUp: return "api_data.api_ship"
-    case .kaisouSlotDeprive: return "api_data.api_ship_data.api_set_ship"
-    case .getMemberShip: return "api_data"
+    case .port: return ["api_data", "api_ship"]
+    case .getMemberShip3: return ["api_data", "api_ship_data"]
+    case .kousyouGetShip: return ["api_data", "api_ship"]
+    case .getMemberShipDeck: return ["api_data", "api_ship_data"]
+    case .kaisouPowerUp: return ["api_data", "api_ship"]
+    case .kaisouSlotDeprive: return ["api_data", "api_ship_data", "api_set_ship"]
+    case .getMemberShip: return ["api_data"]
     }
 }
 
 extension MappingConfiguration {
-    func change(dataKey: String) -> MappingConfiguration {
+    func change(dataKeys: [String]) -> MappingConfiguration {
         return MappingConfiguration(entity: self.entity,
-                                    dataKey: dataKey,
+                                    dataKeys: dataKeys,
                                     primaryKey: self.primaryKey,
                                     compositPrimaryKeys: self.compositPrimaryKeys,
                                     editorStore: self.editorStore,
@@ -52,7 +52,7 @@ class ShipMapper: JSONMapper {
     required init(_ apiResponse: APIResponse) {
         self.apiResponse = apiResponse
         self.configuration = MappingConfiguration(entity: Ship.entity,
-                                                  dataKey: dataKey(apiResponse),
+                                                  dataKeys: dataKeys(apiResponse),
                                                   editorStore: ServerDataStore.oneTimeEditor(),
                                                   ignoreKeys:
             ["api_gomes", "api_gomes2", "api_broken", "api_powup",
@@ -67,7 +67,7 @@ class ShipMapper: JSONMapper {
         // kaisouSlotDepriveでは同時に2種類のデータが入る
         if let api = ShipAPI(rawValue: apiResponse.api),
             api == .kaisouSlotDeprive {
-            let conf = self.configuration.change(dataKey: "api_data.api_ship_data.api_unset_ship")
+            let conf = self.configuration.change(dataKeys: ["api_data", "api_ship_data", "api_unset_ship"])
             ShipMapper(apiResponse, configuration: conf).commit()
         }
     }
index e98405f..6718cb7 100644 (file)
@@ -15,13 +15,13 @@ fileprivate enum SlotItemAPI: String {
     case getMemberRequireInfo = "/kcsapi/api_get_member/require_info"
 }
 
-fileprivate func dataKey(_ apiResponse: APIResponse) -> String {
+fileprivate func dataKeys(_ apiResponse: APIResponse) -> [String] {
     guard let slotItemApi = SlotItemAPI(rawValue: apiResponse.api)
-        else { return "api_data" }
+        else { return ["api_data"] }
     switch slotItemApi {
-    case .kousyouGetShip: return "api_data.api_slotitem"
-    case .getMemberRequireInfo: return "api_data.api_slot_item"
-    default: return "api_data"
+    case .kousyouGetShip: return ["api_data", "api_slotitem"]
+    case .getMemberRequireInfo: return ["api_data", "api_slot_item"]
+    default: return ["api_data"]
     }
 }
 
@@ -34,7 +34,7 @@ class SlotItemMapper: JSONMapper {
     required init(_ apiResponse: APIResponse) {
         self.apiResponse = apiResponse
         self.configuration = MappingConfiguration(entity: SlotItem.entity,
-                                                  dataKey: dataKey(apiResponse),
+                                                  dataKeys: dataKeys(apiResponse),
                                                   editorStore: ServerDataStore.oneTimeEditor())
     }