Last active
August 29, 2015 14:21
-
-
Save kevindelord/be2801426eb3ad862437 to your computer and use it in GitHub Desktop.
This file contains 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
// 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