Updating last thing for setting up tables to Postgres-StORM

This commit is contained in:
Ryan Coyne 2017-11-23 12:19:38 -05:00
parent 6b468a6f22
commit 11d32ea7b6
2 changed files with 8 additions and 6 deletions

View File

@ -82,13 +82,15 @@ extension Bool {
}
//MARK: - Mirror Array:
extension Array where Iterator.Element == Mirror {
var allChildren : [String:Any] {
func allChildren(includingNilValues: Bool=false) -> [String:Any] {
var allChild : [String:Any] = [:]
for mirror in self {
mirror.children.forEach({ (child) in
// Make sure our child has a label & the string describing the value is not nil. (Making optionals supported)
if let label = child.label, String(describing: child.value) != "nil" {
allChild[label] = child.value
if !includingNilValues {
if let label = child.label, String(describing: child.value) != "nil" {
allChild[label] = child.value
}
}
})
}

View File

@ -15,7 +15,7 @@
public protocol CCXMirroring {
func didInitializeSuperclass()
func allChildren() -> [String:Any]
func allChildren(includingNilValues : Bool) -> [String:Any]
}
open class CCXMirror: CCXMirroring {
@ -55,9 +55,9 @@ open class CCXMirror: CCXMirroring {
return mirrors
}
/// This returns all the children, even all the superclass mirrored children. Use allChildren().asData() to return an array of key/values.
public func allChildren() -> [String:Any] {
public func allChildren(includingNilValues : Bool = false) -> [String:Any] {
// Remove out the superclass count which is private:
var children = self.superclassMirrors().allChildren
var children = self.superclassMirrors().allChildren(includingNilValues: includingNilValues)
children.removeValue(forKey: "superclassCount")
return children
}