Last active
October 10, 2015 13:01
-
-
Save sag333ar/829c644eb78a647b287b to your computer and use it in GitHub Desktop.
Load Data from file & parse JSON in Swift 2
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
// Swift 2 | |
// try will throw an error if there any & | |
// catch will directly catch with 'error' | |
let str:String? = NSBundle.mainBundle().pathForResource("IndiaPost", ofType: "json") | |
let data:NSData? = NSData(contentsOfFile: str!) | |
do { | |
let jsonData:AnyObject? = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments) | |
if let arrayData:NSArray = jsonData as? NSArray { | |
self.arrayOfLeftMenuItems = arrayData | |
} | |
} catch { | |
print(error) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment