Last active
February 21, 2020 03:45
-
-
Save sourleangchhean168/f1a663c8524936af35221f410b588677 to your computer and use it in GitHub Desktop.
Revisions
-
sourleangchhean168 revised this gist
Feb 21, 2020 . No changes.There are no files selected for viewing
-
sourleangchhean168 revised this gist
Feb 21, 2020 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -13,3 +13,10 @@ extension Data { let data = Data() print("data \(data!.prettyPrintedJSONString)") // { // "userId": 1, // "id": 1, // "title": "delectus aut autem", // "completed": false // } -
sourleangchhean168 created this gist
Feb 21, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ import Foundation extension Data { var prettyPrintedJSONString: NSString? { /// NSString gives us a nice sanitized debugDescription guard let object = try? JSONSerialization.jsonObject(with: self, options: []), let data = try? JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted]), let prettyPrintedString = NSString(data: data, encoding: String.Encoding.utf8.rawValue) else { return nil } return prettyPrintedString } } //Mark: Using let data = Data() print("data \(data!.prettyPrintedJSONString)")