Skip to content

Instantly share code, notes, and snippets.

@DavidPiper94
Last active April 9, 2020 05:28
Show Gist options
  • Select an option

  • Save DavidPiper94/d7fe6a9ec1b841a411ca2f6e10a0f229 to your computer and use it in GitHub Desktop.

Select an option

Save DavidPiper94/d7fe6a9ec1b841a411ca2f6e10a0f229 to your computer and use it in GitHub Desktop.
Example code for article about SourceKitten - Parsing the result
// 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