add encodeArrayIfPresent
This commit is contained in:
parent
a16c56505e
commit
3842858443
@ -127,12 +127,17 @@ extension KeyedEncodingContainer where Key: CodingKey {
|
||||
}
|
||||
|
||||
///need instance type as input paramaeter list
|
||||
public mutating func encodeArray(_ list:[Model]?, forKey key:KeyedEncodingContainer<K>.Key) throws {
|
||||
public mutating func encodeArray(_ list:[Model], forKey key:KeyedEncodingContainer<K>.Key) throws {
|
||||
var unkeyedContainer = self.nestedUnkeyedContainer(forKey: key)
|
||||
try list?.forEach({ (model) in
|
||||
for model in list {
|
||||
let typeString = type(of: model).identifier
|
||||
let type = ModelRegistry.getType(for: typeString)
|
||||
try type?.mvmencode(unkeyedContainer: &unkeyedContainer, model: model)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
public mutating func encodeArrayIfPresent(_ list:[Model]?, forKey key:KeyedEncodingContainer<K>.Key) throws {
|
||||
guard let models = list else { return }
|
||||
try self.encodeArray(models, forKey: key)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user