Created
December 11, 2016 01:57
-
-
Save alfian0/d188630a5af83ec406ee02e070f240e5 to your computer and use it in GitHub Desktop.
For get JSON localy
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
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