Skip to content

Instantly share code, notes, and snippets.

@PraveenKommuri
Created March 25, 2021 00:03
Show Gist options
  • Save PraveenKommuri/4a76ad8a5a56fe979125ee20620df318 to your computer and use it in GitHub Desktop.
Save PraveenKommuri/4a76ad8a5a56fe979125ee20620df318 to your computer and use it in GitHub Desktop.
Function will read the local json file & return the content as Data object
func readLocalJSONFile(forName name: String) -> Data? {
do {
if let filePath = Bundle.main.path(forResource: name, ofType: "json") {
let fileUrl = URL(fileURLWithPath: filePath)
let data = try Data(contentsOf: fileUrl)
return data
}
} catch {
print("error: \(error)")
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment