Last active
April 9, 2020 05:28
-
-
Save DavidPiper94/d7fe6a9ec1b841a411ca2f6e10a0f229 to your computer and use it in GitHub Desktop.
Example code for article about SourceKitten - Parsing the result
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
| // 1 | |
| func syntaxStructure(from file: File) -> SyntaxStructure? { | |
| do { | |
| // 2 | |
| let structure = try Structure(file: file) | |
| let jsonData = structure.description.data(using: .utf8)! | |
| // 3 | |
| return try JSONDecoder().decode(SyntaxStructure.self, from: jsonData) | |
| // 4 | |
| } catch { | |
| print(error) | |
| return nil | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment