Created
August 16, 2018 21:09
-
-
Save Abhishek9634/809c9a0bee5fe9c537f0bf3e7ad820a0 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
// REQUEST OFFLINE | |
extension Beer { | |
public static func getBeerListOffline(completion: @escaping (_ beerList: [Beer], _ error: Error?) -> Void) { | |
guard let filePath = Bundle.main.url(forResource: "beer", | |
withExtension: "json") else { | |
completion([], AppError.fileNotFound) | |
return | |
} | |
do { | |
let data = try Data.init(contentsOf: filePath) | |
let json = try JSON(data: data) | |
let list: [Beer] = try json.arrayValue.map { try Beer.parse($0) } | |
completion(list, nil) | |
} catch { | |
completion([], error) | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment