Small fix and clean
This commit is contained in:
parent
a7c25f0bdf
commit
441fb0c0e1
@ -18,9 +18,6 @@ public protocol ActionModelProtocol: Model {
|
|||||||
var extraParameters: JSONValueDictionary? { get set }
|
var extraParameters: JSONValueDictionary? { get set }
|
||||||
var analyticsData: JSONValueDictionary? { get set }
|
var analyticsData: JSONValueDictionary? { get set }
|
||||||
|
|
||||||
static var categoryName: String { get }
|
|
||||||
static var categoryCodingKey: String { get }
|
|
||||||
|
|
||||||
// Temporary fix till server changes
|
// Temporary fix till server changes
|
||||||
var title: String? { get set }
|
var title: String? { get set }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,13 +33,7 @@ public struct ModelRegistry {
|
|||||||
/// Registers models for Atomic use.
|
/// Registers models for Atomic use.
|
||||||
public static func register<M: Model>(_ type: M.Type) throws {
|
public static func register<M: Model>(_ type: M.Type) throws {
|
||||||
|
|
||||||
var category: Category
|
var category = categories[M.categoryName] ?? Category(name: M.categoryName, codingKey: M.categoryCodingKey)
|
||||||
|
|
||||||
if let c = categories[M.categoryName] {
|
|
||||||
category = c
|
|
||||||
} else {
|
|
||||||
category = Category(name: M.categoryName, codingKey: M.categoryCodingKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check to ensure the Category/Type combination doesn't exist.
|
// Check to ensure the Category/Type combination doesn't exist.
|
||||||
if category.instanceTypes[M.identifier] != nil {
|
if category.instanceTypes[M.identifier] != nil {
|
||||||
@ -59,11 +53,9 @@ public struct ModelRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static func getCategory(for typeString: String) -> Category? {
|
private static func getCategory(for typeString: String) -> Category? {
|
||||||
|
|
||||||
for (_, value) in categories where value.codingKey == typeString {
|
for (_, value) in categories where value.codingKey == typeString {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +63,7 @@ public struct ModelRegistry {
|
|||||||
return getCategory(for: typeString)?.instanceTypes[name]
|
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 {
|
guard let category = getCategory(for: type) else {
|
||||||
throw ModelRegistry.Error.decoderOther(message: "decodeModelsIfPresent only works for objects implementing the Model protocol")
|
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
|
/// 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 }
|
guard let list = list else { return }
|
||||||
var unkeyedContainer = nestedUnkeyedContainer(forKey: key)
|
var unkeyedContainer = nestedUnkeyedContainer(forKey: key)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user