Created
March 25, 2021 00:03
-
-
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
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
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