Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// This very useful code parses a `.json` file using the library SwiftyJSON.
// Add this in a class, maybe in your Data Manager:
class func addDefaultEntities() {
if let file = NSBundle(forClass:AppDelegate.self).pathForResource(JSON.Constants.FileName, ofType: JSON.Constants.Type) {
if let data = NSData(contentsOfFile: file) {
for (index: String, bookJSON: JSON) in JSON(data:data) {
let dict = bookJSON.dictionaryObject
// do something with the dictionary
// And this in your extensions file:
extension JSON {
struct Constants {
static let FileName = "your_data_local_filename"
static let Type = "json"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.