Skip to content

Instantly share code, notes, and snippets.

@Abhishek9634
Created August 16, 2018 21:09
Show Gist options
  • Save Abhishek9634/809c9a0bee5fe9c537f0bf3e7ad820a0 to your computer and use it in GitHub Desktop.
Save Abhishek9634/809c9a0bee5fe9c537f0bf3e7ad820a0 to your computer and use it in GitHub Desktop.
// 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