diff --git a/Sources/StORM/CCXExtensions.swift b/Sources/StORM/CCXExtensions.swift index 0f7f2f1..347e28e 100644 --- a/Sources/StORM/CCXExtensions.swift +++ b/Sources/StORM/CCXExtensions.swift @@ -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 + } } }) } diff --git a/Sources/StORM/CCXMirroring.swift b/Sources/StORM/CCXMirroring.swift index b8e604d..e9d4884 100644 --- a/Sources/StORM/CCXMirroring.swift +++ b/Sources/StORM/CCXMirroring.swift @@ -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 }