add encode method for model list
This commit is contained in:
parent
eb4e8fd816
commit
5fcbe414ec
@ -125,4 +125,12 @@ extension KeyedEncodingContainer where Key: CodingKey {
|
||||
let encoder = self.superEncoder(forKey: key)
|
||||
try value.encode(to: encoder)
|
||||
}
|
||||
|
||||
///need instance type as input paramaeter list
|
||||
public mutating func encodeArray<T:Model>(_ list:[T]?, forKey key:KeyedEncodingContainer<K>.Key) throws {
|
||||
var unkeyedContainer = self.nestedUnkeyedContainer(forKey: key)
|
||||
try list?.forEach({ (model) in
|
||||
try unkeyedContainer.encode(model)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user