Skip to content

Instantly share code, notes, and snippets.

View lucamegh's full-sized avatar

Luca Meghnagi lucamegh

View GitHub Profile
@lucamegh
lucamegh / ListProperties.swift
Created June 23, 2023 11:19
Lists the stored properties (both public and private) of the given instance.
func listProperties(of subject: Any, maxDepth: Int? = nil) {
func listProperties(of subject: Any, maxDepth: Int?, indentationLevel: Int) {
if let maxDepth, maxDepth == 0 {
return
} else {
let mirror = Mirror(reflecting: subject)
let indentation = String(repeating: "\t", count: indentationLevel)
for case (let label, let value) in mirror.children {
print("\(indentation)▶︎ \(label ?? "<unknown label>"): \(type(of: value)) = \(value)")
@lucamegh
lucamegh / ThemeManager.swift
Last active February 12, 2022 17:11
ThemeManager
// MARK: - Implementation
@dynamicMemberLookup
public class ThemeManager<Theme> {
public var theme: Theme {
didSet {
for (_, handler) in observations {
handler(theme)
}