Skip to content

Instantly share code, notes, and snippets.

@mitulmanish
Created April 8, 2018 02:51
Show Gist options
  • Save mitulmanish/61ce710875b021429319b3ac665f47aa to your computer and use it in GitHub Desktop.
Save mitulmanish/61ce710875b021429319b3ac665f47aa to your computer and use it in GitHub Desktop.
enum ResourceError: Error {
case bundle
}
enum ResourceType: String {
case tv = "tv"
case movies = "movies"
var dataType: String {
switch self {
case .tv, .movies:
return "json"
}
}
func load() throws -> Data? {
guard let location = Bundle.main.path(forResource: rawValue, ofType: dataType) else { throw ResourceError.bundle }
let resourceUrl = URL(fileURLWithPath: location)
do {
return try Data(contentsOf: resourceUrl)
} catch let error {
throw error
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment