Small fix and clean

This commit is contained in:
Pfeil, Scott Robert 2020-02-12 21:35:55 -05:00
parent a7c25f0bdf
commit 441fb0c0e1
2 changed files with 3 additions and 14 deletions

View File

@ -17,9 +17,6 @@ public protocol ActionModelProtocol: Model {
var actionType: String? { get set }
var extraParameters: JSONValueDictionary? { get set }
var analyticsData: JSONValueDictionary? { get set }
static var categoryName: String { get }
static var categoryCodingKey: String { get }
// Temporary fix till server changes
var title: String? { get set }

View File

@ -33,13 +33,7 @@ public struct ModelRegistry {
/// Registers models for Atomic use.
public static func register<M: Model>(_ type: M.Type) throws {
var category: Category
if let c = categories[M.categoryName] {
category = c
} else {
category = Category(name: M.categoryName, codingKey: M.categoryCodingKey)
}
var category = categories[M.categoryName] ?? Category(name: M.categoryName, codingKey: M.categoryCodingKey)
// Check to ensure the Category/Type combination doesn't exist.
if category.instanceTypes[M.identifier] != nil {
@ -59,11 +53,9 @@ public struct ModelRegistry {
}
private static func getCategory(for typeString: String) -> Category? {
for (_, value) in categories where value.codingKey == typeString {
return value
}
return nil
}
@ -71,7 +63,7 @@ public struct ModelRegistry {
return getCategory(for: typeString)?.instanceTypes[name]
}
public static func getCodingKey<T>(for type: T.Type) throws -> AnyCodingKey{
public static func getCodingKey<T>(for type: T.Type) throws -> AnyCodingKey {
guard let category = getCategory(for: type) else {
throw ModelRegistry.Error.decoderOther(message: "decodeModelsIfPresent only works for objects implementing the Model protocol")
}
@ -196,7 +188,7 @@ public extension KeyedEncodingContainer where Key: CodingKey {
}
/// Convenience function for encoding the container into a list of lists of Models. needs instance type as input paramaeter list
mutating func encodeModels2D(_ list: [[Model]]?, forKey key:KeyedEncodingContainer<K>.Key) throws {
mutating func encodeModels2D(_ list: [[Model]]?, forKey key: KeyedEncodingContainer<K>.Key) throws {
guard let list = list else { return }
var unkeyedContainer = nestedUnkeyedContainer(forKey: key)