Skip to content

Instantly share code, notes, and snippets.

View danlozano's full-sized avatar

Daniel Lozano Valdés danlozano

View GitHub Profile
@danlozano
danlozano / PlaceServiceUsageVM.swift
Created September 28, 2017 17:22
Place Service (Usage, ViewModel)
var locationSearchViewModel: LocationSearchViewModel {
let placeService = PlaceApiService(apiClient: apiClient)
let viewModel = LocationSearchViewModel(service: placeService)
viewModel.coordinatorDelegate = self
return viewModel
}
@danlozano
danlozano / PlaceApiService.swift
Last active September 28, 2017 17:14
Place API Service (Implementation)
class PlaceApiService {
let apiClient: ApiClient
// MARK: - Init
init(apiClient: ApiClient) {
self.apiClient = apiClient
}
@danlozano
danlozano / PlaceService.swift
Last active September 28, 2017 17:14
Place Service (Protocol)
protocol PlaceService {
func prefetchPlaces(completion: @escaping (Result<[Place]>) -> Void)
func getPlaces(withText text: String, completion: @escaping (Result<[Place]>) -> Void)
}
@danlozano
danlozano / TripsViewModel.swift
Created September 28, 2017 16:46
View Data Usage from View Model
func tripCount() -> Int {
return trips.count
}
func trip(forRow row: Int) -> TripViewDataType {
let trip = trips[row]
return TripViewData(trip: trip)
}
@danlozano
danlozano / TripViewData.swift
Created September 28, 2017 16:37
Trip View Data (Implementation)
struct TripViewData: TripViewDataType {
var departureTime: String {
return DateHelper.timeFormatter.string(from: trip.departure)
}
var shouldShowTerminals: Bool {
return !(trip is Flight)
}
@danlozano
danlozano / TripViewDataType.swift
Last active September 28, 2017 16:38
Trip View Data (Protocol)
protocol TripViewDataType {
var departureTime: String { get }
var shouldShowTerminals: Bool { get }
var departureTerminal: String { get }
var accentColor: UIColor { get }
@danlozano
danlozano / LocationSearchViewController.swift
Last active December 16, 2017 07:50
Location Search View Controller
class LocationSearchViewController: UIViewController {
// MARK: - Properties
var viewModel: LocationSearchViewModelType! {
didSet {
viewModel.viewDelegate = self
}
}
extension LocationSearchViewModel: LocationSearchViewModelType {
// MARK: - Data Source
var shouldShowHeader: Bool {
return !isSearching
}
var headerText: String {
return "Search"
@danlozano
danlozano / LocationSearchViewModel.swift
Last active September 27, 2017 23:26
Location Search View Model (Main Implementation)
class LocationSearchViewModel {
// MARK: - Delegates
weak var coordinatorDelegate: LocationSearchViewModelCoordinatorDelegate?
weak var viewDelegate: LocationSearchViewModelViewDelegate?
// MARK: - Properties
@danlozano
danlozano / LocationSearchViewModelType.swift
Last active September 27, 2017 23:20
Location Search View Model (Protocols)
protocol LocationSearchViewModelType {
weak var viewDelegate: LocationSearchViewModelViewDelegate? { get set }
// Data Source
var shouldShowHeader: Bool { get }
var headerText: String { get }