let apiResponse: APIResponse
let configuration = MappingConfiguration(entity: AirBase.entity,
dataKeys: ["api_data", "api_air_base"],
- compositPrimaryKeys: ["area_id", "rid"],
+ primaryKeys: ["area_id", "rid"],
editorStore: ServerDataStore.oneTimeEditor())
required init(_ apiResponse: APIResponse) {
struct MappingConfiguration<T: NSManagedObject> {
let entity: Entity<T>
let dataKeys: [String]
- let primaryKey: String
- let compositPrimaryKeys: [String]?
+ let primaryKeys: [String]
let editorStore: CoreDataAccessor
let ignoreKeys: [String]
init(entity: Entity<T>,
dataKeys: [String] = ["api_data"],
- primaryKey: String = "id",
- compositPrimaryKeys: [String]? = nil,
+ primaryKeys: [String] = ["id"],
editorStore: CoreDataAccessor,
ignoreKeys: [String] = []) {
self.entity = entity
self.dataKeys = dataKeys
- self.primaryKey = primaryKey
- self.compositPrimaryKeys = compositPrimaryKeys
+ self.primaryKeys = primaryKeys
self.editorStore = editorStore
self.ignoreKeys = ignoreKeys
}
}
}
private var sortDescriptors: [NSSortDescriptor] {
- let keys = configuration.compositPrimaryKeys ?? [configuration.primaryKey]
- return keys.map { NSSortDescriptor(key: $0, ascending: true) }
+ return configuration.primaryKeys.map { NSSortDescriptor(key: $0, ascending: true) }
}
private func objectSearch(_ objects: [ObjectType], _ element: JSON) -> ObjectType? {
- let keys = configuration.compositPrimaryKeys ?? [configuration.primaryKey]
- let keyPiar = keys.map { (key: $0, apiKey: "api_\($0)") }
+ let keyPiar = configuration.primaryKeys.map { (key: $0, apiKey: "api_\($0)") }
return objects.binarySearch {
for piar in keyPiar {
guard let v1 = $0.value(forKey: piar.key)
func change(dataKeys: [String]) -> MappingConfiguration {
return MappingConfiguration(entity: self.entity,
dataKeys: dataKeys,
- primaryKey: self.primaryKey,
- compositPrimaryKeys: self.compositPrimaryKeys,
+ primaryKeys: self.primaryKeys,
editorStore: self.editorStore,
ignoreKeys: self.ignoreKeys)
}