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
[ | |
{name: 'Afghanistan', code: 'AF'}, | |
{name: 'Åland Islands', code: 'AX'}, | |
{name: 'Albania', code: 'AL'}, | |
{name: 'Algeria', code: 'DZ'}, | |
{name: 'American Samoa', code: 'AS'}, | |
{name: 'AndorrA', code: 'AD'}, | |
{name: 'Angola', code: 'AO'}, | |
{name: 'Anguilla', code: 'AI'}, | |
{name: 'Antarctica', code: 'AQ'}, |
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
extension BeerListViewController: UISearchBarDelegate { | |
func setupSearchBar() { | |
self.searchBar.delegate = self | |
} | |
func searchBar(_ searchBar: UISearchBar, | |
textDidChange searchText: String) { | |
self.viewModel.filterSearch( |
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
extension BeerListViewController: UITableViewDelegate, UITableViewDataSource { | |
func tableView(_ tableView: UITableView, | |
numberOfRowsInSection section: Int) -> Int { | |
return self.viewModel.itemCount | |
} | |
func tableView(_ tableView: UITableView, | |
cellForRowAt indexPath: IndexPath) -> UITableViewCell { |
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
private func setupViewModel() { | |
self.viewModel.reloadHandler = { | |
self.tableView.reloadData() | |
} | |
self.showLoader() | |
self.viewModel.fetchItems { _ in | |
self.hideLoader() |
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
struct BeerCellModel { | |
var beer: Beer | |
} | |
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
// | |
// BeerListViewModel.swift | |
// BeerCrafts | |
// | |
// Created by Abhishek on 27/07/18. | |
// Copyright © 2018 Abhishek. All rights reserved. | |
// | |
import Foundation |
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
// | |
// BeerTableViewCell.swift | |
// BeerCrafts | |
// | |
// Created by Abhishek on 29/06/18. | |
// Copyright © 2018 Abhishek. All rights reserved. | |
// | |
import UIKit |
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 |
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
import Foundation | |
import JSONParsing | |
public final class Beer: JSONParseable { | |
public var abv: String | |
public var ibu: String | |
public var id: Int | |
public var name: String |
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
[ | |
{ | |
"abv": "0.05", | |
"ibu": "", | |
"id": 1436, | |
"name": "Pub Beer", | |
"style": "American Pale Lager", | |
"ounces": 12 | |
}, | |
{ |