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 Bool { | |
mutating func toggle() { | |
self = !self | |
} | |
} |
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
class ViewController: UIViewController { | |
let viewModel = ViewModel() | |
var jobs = [Job]() | |
@IBOutlet weak var tableView: UITableView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
viewModel.getJobs(closure: { [unowned self] (result) in |
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
class ViewController: UIViewController { | |
let viewModel = ViewModel() | |
var jobs = [Job]() | |
@IBOutlet weak var tableView: UITableView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
viewModel.getJobs(closure: { (result) in |
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
class ViewController: UIViewController { | |
let viewModel = ViewModel() | |
var jobs = [Job]() | |
@IBOutlet weak var tableView: UITableView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
viewModel.getJobs(closure: { (result) in |
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 ViewModelError: Error { | |
case urlError(String) | |
case apiClientError(ApiClientError) | |
} | |
final class ViewModel { | |
typealias Closure = (Result) -> () | |
enum Result { |
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 Constants { | |
static let jobsUrl = "https://jobs.github.com/positions.json" | |
} | |
enum ApiClientError: Error { | |
case jsonFormat(String) | |
case responseError(String) | |
} | |
final class ApiClient { |
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
func get(url: URL, closure: @escaping Closure) |
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
typealias Closure = (Response) -> () |
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 Response { | |
case result([Job]) | |
case error(ApiClientError) | |
} |
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
protocol ApiClientDelegate { | |
func didFinishLoadingWithJobs(_ jobs: [Job]?) | |
func didFailedLoadingWithError(_ error: ApiClientError) | |
} |