Created
June 1, 2022 15:03
-
-
Save NikolajMosbaek/eaa72c71227ed10e9c1e1b4eddcf679d to your computer and use it in GitHub Desktop.
This code will func a function on every value on any object
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
func mirror(_ value: Any, using function: (Any) -> Void) { | |
let mirror = Mirror(reflecting: value) | |
for child in mirror.children { | |
function(child.value) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From HWS+ https://www.hackingwithswift.com/plus/advanced-swift/runtime-reflection-with-mirror