Skip to content

Instantly share code, notes, and snippets.

@alfian0
Created December 11, 2016 01:57
Show Gist options
  • Save alfian0/d188630a5af83ec406ee02e070f240e5 to your computer and use it in GitHub Desktop.
Save alfian0/d188630a5af83ec406ee02e070f240e5 to your computer and use it in GitHub Desktop.
For get JSON localy
class GetJSONLocalFile {
class func fromFile(fileName: String) -> String? {
guard let path: String = NSBundle.mainBundle().pathForResource(fileName, ofType: "json") else {
print("Error!, Unable to load \(fileName).json")
return nil
}
do {
guard let data: String = try String(contentsOfFile: path) else {
return nil
}
return data
} catch {
fatalError("Error, Unable to parse \(fileName).json")
}
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment