Created
April 13, 2021 20:36
-
-
Save jaredh159/5116e92e9b81830cb90d9f019853c449 to your computer and use it in GitHub Desktop.
Recursively Log out an NSDictionary
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 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