Created
October 11, 2017 17:36
-
-
Save ryantxr/9e40ee7c7416a1b0732e29d70630b374 to your computer and use it in GitHub Desktop.
JSON output from API Call
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
/* | |
JSON from API calls are provided as Data objects, not strings. | |
While debugging, it is often necessary to output the JSON | |
string somewhere. This snippet does that. | |
*/ | |
if let data = data { | |
print("JSON = " + String(data: data, encoding: .utf8)! ) | |
} | |
// Notice the use of ! since the String constructor might fail. | |
// Here is an alternative if you want to avoid forced unwrap | |
if let data = data { | |
print("JSON = " + String(data: data, encoding: .utf8) ?? "Error converting to string" ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment