Skip to content

Instantly share code, notes, and snippets.

@Gujci
Created July 18, 2016 13:30
Show Gist options
  • Save Gujci/8127efd4bfea244a2c07b43acac2fc11 to your computer and use it in GitHub Desktop.
Save Gujci/8127efd4bfea244a2c07b43acac2fc11 to your computer and use it in GitHub Desktop.
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