Skip to content

Instantly share code, notes, and snippets.

@iAmrSalman
Created December 12, 2017 12:15
Show Gist options
  • Save iAmrSalman/7715c615245d9be67e4e6e2623fff868 to your computer and use it in GitHub Desktop.
Save iAmrSalman/7715c615245d9be67e4e6e2623fff868 to your computer and use it in GitHub Desktop.
[Loopable] #protocol #swift
protocol Loopable {
var allProperties: [String: Any] { get }
}
extension Loopable {
var allProperties: [String: Any] {
var result = [String: Any]()
Mirror(reflecting: self).children.forEach { child in
if let property = child.label {
result[property] = child.value
}
}
return result
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment