Created
July 18, 2016 13:30
-
-
Save Gujci/8127efd4bfea244a2c07b43acac2fc11 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public protocol OptionalValueObservable { | |
var isComplete: Bool {get} | |
var hasAnyProperty: Bool {get} | |
} | |
public extension OptionalValueObservable { | |
var isComplete: Bool { | |
get { | |
return Mirror(reflecting: self).children.reduce(true) { acc, val in | |
let subMirror = Mirror(reflecting: val.value) | |
return acc && (subMirror.displayStyle == .Optional ? subMirror.children.count > 0 : true) | |
} | |
} | |
} | |
var hasAnyProperty: Bool { | |
get { | |
return Mirror(reflecting: self).children.reduce(false) { acc, val in | |
let subMirror = Mirror(reflecting: val.value) | |
return acc || (subMirror.displayStyle == .Optional ? subMirror.children.count > 0 : true) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment