Skip to content

Instantly share code, notes, and snippets.

View ykpoh's full-sized avatar

Yk Poh ykpoh

  • Melaka, Malaysia
View GitHub Profile
class LaunchListViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet var tableView: UITableView!
var viewModel: LaunchListViewModelType = LaunchListViewModel()
var disposeBag: DisposeBag!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
tableView.delegate = self
struct LaunchResponse: Codable, Equatable {
let docs: [Launch]?
}
struct Launch: Codable, Equatable {
let id: String?
let name: String?
let details: String?
let date_utc: Date?
let upcoming: Bool?
let success: Bool?
let rocket: String?
init(id: String?, name: String?, details: String?, date_utc: Date?, upcoming: Bool?, success: Bool?, rocket: String?) {
import Alamofire
protocol APIServiceProtocol {
func fetchLaunchesWithQuery(startDate: Date, endDate: Date, completion: @escaping (LaunchResponse?, Error?, AFDataResponse<Any>) -> Void) -> DataRequestProtocol
func fetchRocket(rocketName: String, completion: @escaping (Rocket?, Error?, AFDataResponse<Any>) -> Void) -> DataRequestProtocol
}
extension APIServiceProtocol {
@discardableResult func fetchLaunchesWithQuery(startDate: Date = Calendar.current.date(byAdding: .year, value: -3, to: Date()) ?? Date(), endDate: Date = Date(), completion: @escaping (LaunchResponse?, Error?, AFDataResponse<Any>) -> Void) -> DataRequestProtocol {
return fetchLaunchesWithQuery(startDate: startDate, endDate: endDate, completion: completion)
import Foundation
import RxCocoa
protocol LaunchListTableViewCellViewModelType { // 1
var launch: BehaviorRelay<Launch?> { get }
var launchNumber: BehaviorRelay<String?> { get }
var detail: BehaviorRelay<String?> { get }
var hideDetail: BehaviorRelay<Bool> { get }
var dateTime: BehaviorRelay<String?> { get }
var statusString: BehaviorRelay<String?> { get }
protocol LaunchListViewModelType {
var launchViewModels: BehaviorRelay<[LaunchListTableViewCellViewModel]> { get } // 1
var notifyError: BehaviorRelay<Error?> { get } // 2
func fetchLaunchesWithQuery() // 3
}
class LaunchListViewModel: LaunchListViewModelType {
let apiService: APIServiceProtocol // 4
import UIKit
import RxSwift
class LaunchListViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet var tableView: UITableView!
var viewModel: LaunchListViewModelType = LaunchListViewModel()
var disposeBag: DisposeBag!
override func viewDidLoad() {
super.viewDidLoad()
import Alamofire
protocol APIServiceProtocol { // 1
func fetchLaunchesWithQuery(startDate: Date, endDate: Date, completion: @escaping (LaunchResponse?, Error?, AFDataResponse<Any>) -> Void) -> DataRequestProtocol
func fetchRocket(rocketName: String, completion: @escaping (Rocket?, Error?, AFDataResponse<Any>) -> Void) -> DataRequestProtocol
}
extension APIServiceProtocol { // 2
@discardableResult func fetchLaunchesWithQuery(startDate: Date = Calendar.current.date(byAdding: .year, value: -3, to: Date()) ?? Date(), endDate: Date = Date(), completion: @escaping (LaunchResponse?, Error?, AFDataResponse<Any>) -> Void) -> DataRequestProtocol {
return fetchLaunchesWithQuery(startDate: startDate, endDate: endDate, completion: completion)
{
"docs": [
{
"fairings": {
"reused": false,
"recovery_attempt": false,
"recovered": false,
"ships": []
},
"links": {
{
"height": {
"meters": 70,
"feet": 229.6
},
"diameter": {
"meters": 12.2,
"feet": 39.9
},
"mass": {