Cleanup for names and stack
This commit is contained in:
parent
8451a045bc
commit
b6f5010b76
@ -50,7 +50,7 @@
|
||||
8876D5F31FB50AB000EB2E3D /* UIFont+MFSpacing.m in Sources */ = {isa = PBXBuildFile; fileRef = 8876D5E51FB50AB000EB2E3D /* UIFont+MFSpacing.m */; };
|
||||
8876D5F41FB50AB000EB2E3D /* UILabel+MFCustom.h in Headers */ = {isa = PBXBuildFile; fileRef = 8876D5E61FB50AB000EB2E3D /* UILabel+MFCustom.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
8876D5F51FB50AB000EB2E3D /* UILabel+MFCustom.m in Sources */ = {isa = PBXBuildFile; fileRef = 8876D5E71FB50AB000EB2E3D /* UILabel+MFCustom.m */; };
|
||||
946EE1A3237B59C30036751F /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1A2237B59C30036751F /* Model.swift */; };
|
||||
946EE1A3237B59C30036751F /* ModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1A2237B59C30036751F /* ModelProtocol.swift */; };
|
||||
946EE1A7237B5B1C0036751F /* ModelRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1A6237B5B1C0036751F /* ModelRegistry.swift */; };
|
||||
946EE1AB237B5C940036751F /* Decoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1AA237B5C940036751F /* Decoder.swift */; };
|
||||
946EE1B0237B5EF70036751F /* JSONHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1AF237B5EF70036751F /* JSONHelper.swift */; };
|
||||
@ -201,7 +201,7 @@
|
||||
8876D5E51FB50AB000EB2E3D /* UIFont+MFSpacing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIFont+MFSpacing.m"; sourceTree = "<group>"; };
|
||||
8876D5E61FB50AB000EB2E3D /* UILabel+MFCustom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UILabel+MFCustom.h"; sourceTree = "<group>"; };
|
||||
8876D5E71FB50AB000EB2E3D /* UILabel+MFCustom.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UILabel+MFCustom.m"; sourceTree = "<group>"; };
|
||||
946EE1A2237B59C30036751F /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = "<group>"; };
|
||||
946EE1A2237B59C30036751F /* ModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelProtocol.swift; sourceTree = "<group>"; };
|
||||
946EE1A6237B5B1C0036751F /* ModelRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelRegistry.swift; sourceTree = "<group>"; };
|
||||
946EE1AA237B5C940036751F /* Decoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Decoder.swift; sourceTree = "<group>"; };
|
||||
946EE1AF237B5EF70036751F /* JSONHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONHelper.swift; sourceTree = "<group>"; };
|
||||
@ -424,7 +424,7 @@
|
||||
946EE1A8237B5C650036751F /* Model */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
946EE1A2237B59C30036751F /* Model.swift */,
|
||||
946EE1A2237B59C30036751F /* ModelProtocol.swift */,
|
||||
946EE1A6237B5B1C0036751F /* ModelRegistry.swift */,
|
||||
);
|
||||
path = Model;
|
||||
@ -936,7 +936,7 @@
|
||||
D2DEDCB723C63F3B00C44CC4 /* Clamping.swift in Sources */,
|
||||
01DF561421F90ADC00CC099B /* Dictionary+MFConvenience.swift in Sources */,
|
||||
AFBB96B11FBA3B590008D868 /* MVMCoreDispatchUtility.m in Sources */,
|
||||
946EE1A3237B59C30036751F /* Model.swift in Sources */,
|
||||
946EE1A3237B59C30036751F /* ModelProtocol.swift in Sources */,
|
||||
01F2A05023A82D0800D954D8 /* ActionTopAlertModel.swift in Sources */,
|
||||
AFBB965B1FBA3A570008D868 /* FreeBeeUrlObject.m in Sources */,
|
||||
AFEA17A9209B6A1C00BC6740 /* MVMCoreBlockOperation.m in Sources */,
|
||||
|
||||
@ -12,7 +12,7 @@ public enum ActionCodingKey: String, CodingKey {
|
||||
case actionType
|
||||
}
|
||||
|
||||
public protocol ActionModelProtocol: Model {
|
||||
public protocol ActionModelProtocol: ModelProtocol {
|
||||
|
||||
var actionType: String? { get set }
|
||||
var extraParameters: JSONValueDictionary? { get set }
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Model.swift
|
||||
// ModelProtocol.swift
|
||||
// MVMCore
|
||||
//
|
||||
// Created by Matt Brunce on 11/12/19.
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol Model: Codable {
|
||||
public protocol ModelProtocol: Codable {
|
||||
|
||||
/// The key name of the molecule
|
||||
static var identifier: String { get }
|
||||
@ -32,7 +32,7 @@ public protocol Model: Codable {
|
||||
func encode(unkeyedContainer: inout UnkeyedEncodingContainer) throws
|
||||
}
|
||||
|
||||
extension Model {
|
||||
extension ModelProtocol {
|
||||
|
||||
static public func decode<K: CodingKey>(keyedContainer: KeyedDecodingContainer<K>, codingKey: K) throws -> Self? {
|
||||
return try keyedContainer.decodeIfPresent(self, forKey: codingKey)
|
||||
@ -25,19 +25,19 @@ public struct ModelRegistry {
|
||||
private struct Category {
|
||||
var name: String
|
||||
var codingKey: String
|
||||
var instanceTypes: [String: Model.Type] = [:]
|
||||
var instanceTypes: [String: ModelProtocol.Type] = [:]
|
||||
}
|
||||
|
||||
private static var categories: [String: Category] = [:]
|
||||
|
||||
/// Registers models for Atomic use.
|
||||
public static func register<M: Model>(_ type: M.Type) throws {
|
||||
public static func register<M: ModelProtocol>(_ type: M.Type) throws {
|
||||
|
||||
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 {
|
||||
throw ModelRegistry.Error.other(message: "Model: \(M.identifier) already exists in Category: \(M.categoryName)")
|
||||
throw ModelRegistry.Error.other(message: "ModelProtocol: \(M.identifier) already exists in Category: \(M.categoryName)")
|
||||
}
|
||||
|
||||
category.instanceTypes[M.identifier] = type
|
||||
@ -48,7 +48,7 @@ public struct ModelRegistry {
|
||||
return categories["\(T.self)"]
|
||||
}
|
||||
|
||||
public static func getType<T>(for name: String, with type: T.Type) -> Model.Type? {
|
||||
public static func getType<T>(for name: String, with type: T.Type) -> ModelProtocol.Type? {
|
||||
return getCategory(for: type)?.instanceTypes[name]
|
||||
}
|
||||
|
||||
@ -59,13 +59,13 @@ public struct ModelRegistry {
|
||||
return nil
|
||||
}
|
||||
|
||||
public static func getType(for name: String, with typeString: String) -> Model.Type? {
|
||||
public static func getType(for name: String, with typeString: String) -> ModelProtocol.Type? {
|
||||
return getCategory(for: typeString)?.instanceTypes[name]
|
||||
}
|
||||
|
||||
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")
|
||||
throw ModelRegistry.Error.decoderOther(message: "decodeModelsIfPresent only works for objects implementing the ModelProtocol protocol")
|
||||
}
|
||||
|
||||
return AnyCodingKey(category.codingKey)
|
||||
@ -79,7 +79,7 @@ extension KeyedDecodingContainer where Key: CodingKey {
|
||||
/// Decodes to a registered model based on the identifier
|
||||
public func decodeModel<M, TypeKey: CodingKey>(codingKey: KeyedDecodingContainer<K>.Key, typeCodingKey: TypeKey) throws -> M {
|
||||
|
||||
guard let model: Model = try decodeModelIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else {
|
||||
guard let model: ModelProtocol = try decodeModelIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else {
|
||||
MVMCoreLoggingHandler.logDebugMessage(withDelegate: "ModelRegistry Error decoderErrorObjectNotPresent: \(codingKey)")
|
||||
throw ModelRegistry.Error.decoderErrorObjectNotPresent
|
||||
}
|
||||
@ -103,7 +103,7 @@ extension KeyedDecodingContainer where Key: CodingKey {
|
||||
else { return nil }
|
||||
|
||||
guard let type = ModelRegistry.getType(for: identifier, with: typeCodingKey.stringValue) else {
|
||||
MVMCoreLoggingHandler.logDebugMessage(withDelegate: "Model not mapped: \(identifier)")
|
||||
MVMCoreLoggingHandler.logDebugMessage(withDelegate: "ModelProtocol not mapped: \(identifier)")
|
||||
throw ModelRegistry.Error.decoderErrorModelNotMapped
|
||||
}
|
||||
|
||||
@ -119,7 +119,7 @@ extension KeyedDecodingContainer where Key: CodingKey {
|
||||
}
|
||||
|
||||
/// Decodes an array of registered model based on the identifiers, optional.
|
||||
public func decodeModelsIfPresent<TypeKey: CodingKey>(codingKey: KeyedDecodingContainer<K>.Key, typeCodingKey: TypeKey) throws -> [Model]? {
|
||||
public func decodeModelsIfPresent<TypeKey: CodingKey>(codingKey: KeyedDecodingContainer<K>.Key, typeCodingKey: TypeKey) throws -> [ModelProtocol]? {
|
||||
guard contains(codingKey),
|
||||
var container = try? self.nestedUnkeyedContainer(forKey: codingKey)
|
||||
else { return nil }
|
||||
@ -128,8 +128,8 @@ extension KeyedDecodingContainer where Key: CodingKey {
|
||||
}
|
||||
|
||||
/// Decodes an array of registered model based on the identifiers.
|
||||
public func decodeModels<TypeKey: CodingKey>(codingKey: KeyedDecodingContainer<K>.Key, typeCodingKey: TypeKey) throws -> [Model] {
|
||||
guard let models: [Model] = try decodeModelsIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else {
|
||||
public func decodeModels<TypeKey: CodingKey>(codingKey: KeyedDecodingContainer<K>.Key, typeCodingKey: TypeKey) throws -> [ModelProtocol] {
|
||||
guard let models: [ModelProtocol] = try decodeModelsIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else {
|
||||
MVMCoreLoggingHandler.logDebugMessage(withDelegate: "ModelRegistry Error decoderErrorObjectNotPresent: \(codingKey)")
|
||||
throw ModelRegistry.Error.decoderErrorObjectNotPresent
|
||||
}
|
||||
@ -137,7 +137,7 @@ extension KeyedDecodingContainer where Key: CodingKey {
|
||||
}
|
||||
|
||||
/// Decodes an array with arrays of models based on the identifiers, optional.
|
||||
public func decodeModels2DIfPresent<TypeKey: CodingKey>(codingKey: KeyedDecodingContainer<K>.Key, typeCodingKey: TypeKey) throws -> [[Model]]? {
|
||||
public func decodeModels2DIfPresent<TypeKey: CodingKey>(codingKey: KeyedDecodingContainer<K>.Key, typeCodingKey: TypeKey) throws -> [[ModelProtocol]]? {
|
||||
guard contains(codingKey),
|
||||
var container = try? nestedUnkeyedContainer(forKey: codingKey)
|
||||
else { return nil }
|
||||
@ -146,8 +146,8 @@ extension KeyedDecodingContainer where Key: CodingKey {
|
||||
}
|
||||
|
||||
/// Decodes an array with arrays of models based on the identifiers.
|
||||
public func decodeModels2D<TypeKey: CodingKey>(codingKey: KeyedDecodingContainer<K>.Key, typeCodingKey: TypeKey) throws -> [[Model]] {
|
||||
guard let models: [[Model]] = try decodeModels2DIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else {
|
||||
public func decodeModels2D<TypeKey: CodingKey>(codingKey: KeyedDecodingContainer<K>.Key, typeCodingKey: TypeKey) throws -> [[ModelProtocol]] {
|
||||
guard let models: [[ModelProtocol]] = try decodeModels2DIfPresent(codingKey: codingKey, typeCodingKey: typeCodingKey) else {
|
||||
MVMCoreLoggingHandler.logDebugMessage(withDelegate: "ModelRegistry Error decoderErrorObjectNotPresent: \(codingKey)")
|
||||
throw ModelRegistry.Error.decoderErrorObjectNotPresent
|
||||
}
|
||||
@ -158,7 +158,7 @@ extension KeyedDecodingContainer where Key: CodingKey {
|
||||
public extension KeyedEncodingContainer where Key: CodingKey {
|
||||
|
||||
/// Encodes a model, optional.
|
||||
mutating func encodeModelIfPresent(_ value: Model?, forKey key: KeyedEncodingContainer<K>.Key) throws {
|
||||
mutating func encodeModelIfPresent(_ value: ModelProtocol?, forKey key: KeyedEncodingContainer<K>.Key) throws {
|
||||
if let value = value {
|
||||
let encoder = superEncoder(forKey: key)
|
||||
try value.encode(to: encoder)
|
||||
@ -166,18 +166,18 @@ public extension KeyedEncodingContainer where Key: CodingKey {
|
||||
}
|
||||
|
||||
/// Encodes a model.
|
||||
mutating func encodeModel(_ value: Model, forKey key: KeyedEncodingContainer<K>.Key) throws {
|
||||
mutating func encodeModel(_ value: ModelProtocol, forKey key: KeyedEncodingContainer<K>.Key) throws {
|
||||
let encoder = superEncoder(forKey: key)
|
||||
try value.encode(to: encoder)
|
||||
}
|
||||
|
||||
/// Encodes an array of models
|
||||
mutating func encodeModels(_ list: [Model], forKey key:KeyedEncodingContainer<K>.Key) throws {
|
||||
mutating func encodeModels(_ list: [ModelProtocol], forKey key:KeyedEncodingContainer<K>.Key) throws {
|
||||
try encodeModelsIfPresent(list, forKey: key)
|
||||
}
|
||||
|
||||
/// Encodes an array of models, optional, need instance type as input paramaeter list
|
||||
mutating func encodeModelsIfPresent(_ list: [Model]?, forKey key:KeyedEncodingContainer<K>.Key) throws {
|
||||
mutating func encodeModelsIfPresent(_ list: [ModelProtocol]?, forKey key:KeyedEncodingContainer<K>.Key) throws {
|
||||
|
||||
guard let list = list else { return }
|
||||
var unkeyedContainer = nestedUnkeyedContainer(forKey: key)
|
||||
@ -188,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: [[ModelProtocol]]?, forKey key: KeyedEncodingContainer<K>.Key) throws {
|
||||
|
||||
guard let list = list else { return }
|
||||
var unkeyedContainer = nestedUnkeyedContainer(forKey: key)
|
||||
@ -205,9 +205,9 @@ public extension KeyedEncodingContainer where Key: CodingKey {
|
||||
public extension UnkeyedDecodingContainer {
|
||||
|
||||
/// Decodes the container into a list of Models.
|
||||
mutating func decodeModelsIfPresent<TypeKey: CodingKey>(typeCodingKey: TypeKey) throws -> [Model]? {
|
||||
mutating func decodeModelsIfPresent<TypeKey: CodingKey>(typeCodingKey: TypeKey) throws -> [ModelProtocol]? {
|
||||
|
||||
var models = [Model]()
|
||||
var models = [ModelProtocol]()
|
||||
var containerCopy = self
|
||||
|
||||
while !containerCopy.isAtEnd {
|
||||
@ -227,9 +227,9 @@ public extension UnkeyedDecodingContainer {
|
||||
}
|
||||
|
||||
/// Convenience function for decoding the container into a list of lists of Models.
|
||||
mutating func decodeModels2DIfPresent<TypeKey: CodingKey>(typeCodingKey: TypeKey) throws -> [[Model]]? {
|
||||
mutating func decodeModels2DIfPresent<TypeKey: CodingKey>(typeCodingKey: TypeKey) throws -> [[ModelProtocol]]? {
|
||||
|
||||
var modelLists = [[Model]]()
|
||||
var modelLists = [[ModelProtocol]]()
|
||||
var containerCopy = self
|
||||
|
||||
while !containerCopy.isAtEnd {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user