Created
April 8, 2018 02:51
-
-
Save mitulmanish/61ce710875b021429319b3ac665f47aa 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
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