Making the mirroring support optionals & if the value is nil, it does not add it in the dictionary or asData array on the save

This commit is contained in:
Ryan Coyne 2017-11-23 10:48:11 -05:00
parent 7fbe972873
commit 6b468a6f22
2 changed files with 4 additions and 14 deletions

View File

@ -86,30 +86,19 @@ extension Array where Iterator.Element == Mirror {
var allChild : [String:Any] = [:] var allChild : [String:Any] = [:]
for mirror in self { for mirror in self {
mirror.children.forEach({ (child) in mirror.children.forEach({ (child) in
if let label = child.label { // 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 allChild[label] = child.value
} }
}) })
} }
return allChild return allChild
} }
// var allChildrenData : [(String,Any)] {
// var allChild : [(String,Any)] = []
// for mirror in self {
// mirror.children.forEach({ (child) in
// if child.label.isNotNil {
// allChild.append((child.label!, child.value))
// }
// })
// }
// return allChild
// }
} }
extension Dictionary where Key == String, Value == Any { extension Dictionary where Key == String, Value == Any {
public func asData() -> [(String, Any)] { public func asData() -> [(String, Any)] {
var data : [(String,Any)] = [] var data : [(String,Any)] = []
// Remove out the superclass count which is private:
for row in self { for row in self {
data.append(row) data.append(row)
} }

View File

@ -19,7 +19,8 @@ public protocol CCXMirroring {
} }
open class CCXMirror: CCXMirroring { open class CCXMirror: CCXMirroring {
private var superclassCount = 0 // The superclass count will include CCXMirror, StORM, & Postgres-StORM by the time we get to the subclasses we need to process.
private var superclassCount = 3
public func didInitializeSuperclass() { public func didInitializeSuperclass() {
self.superclassCount += 1 self.superclassCount += 1
} }