Skip to content

Instantly share code, notes, and snippets.

@jaredh159
Created April 13, 2021 20:36
Show Gist options
  • Save jaredh159/5116e92e9b81830cb90d9f019853c449 to your computer and use it in GitHub Desktop.
Save jaredh159/5116e92e9b81830cb90d9f019853c449 to your computer and use it in GitHub Desktop.
Recursively Log out an NSDictionary
func logDict(_ dict: NSDictionary) {
for (key, value) in dict {
guard let strKey = key as? String else {
os_log("[NSDictionary] unexpected non-string key type=%s", String(describing: type(of: key)))
continue
}
switch value {
case let string as String:
os_log("[NSDictionary] %s = (String) %s", strKey, string)
case let int as Int:
os_log("[NSDictionary] %s = (Int) %d", strKey, int)
case let subDict as NSDictionary:
logDict(subDict)
default:
os_log(
"[NSDictionary] %s = (%s) %s", strKey, String(describing: type(of: value)),
String(describing: value))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment