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 Combine | |
extension AnyCancellable { | |
func add(to cancellables: inout [AnyCancellable]) { | |
cancellables.append(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
final class ViewModel { | |
// 1. | |
@Published var operation: MathOperation? | |
@Published var operationText: String? | |
@Published var firstNumberText: String? | |
@Published var secondNumberText: String? | |
@Published var result: String? | |
@Published private var firstNumber: Int? | |
@Published private var secondNumber: Int? |
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
final class ViewController: UIViewController { | |
// ... | |
// MARK: - Helper methods - | |
private func calculateResult() { | |
guard let firstNumber = Int(firstNumberTextField.text ?? "") | |
, let secondNumber = Int(secondNumberTextField.text ?? "") | |
, let selectedOperation = self.selectedOperation | |
else { | |
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
final class ViewController: UIViewController { | |
// ... | |
// MARK: - Life Cycle - | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
firstNumberTextField.addTarget(self, | |
action: #selector(firstNumberTextFieldChanged), | |
for: .editingChanged |
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
final class ViewController: UIViewController | |
// MARK: - Views - | |
@IBOutlet private weak var firstNumberTextField: UITextField! | |
@IBOutlet private weak var secondNumberTextField: UITextField! | |
@IBOutlet private weak var operationTextField: UITextField! | |
@IBOutlet private weak var resultLabel: UILabel! | |
// ... | |
} |
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 UIKit | |
enum Dependencies { | |
struct Name { | |
let rawValue: String | |
static let `default` = Name(rawValue: "__default__") | |
} | |
final class Container { | |
private var dependencies: [(key: Dependencies.Name, value: Any)] = [] |
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
// | |
// ContentView.swift | |
// FirestoreTest | |
// | |
// Created by MAC on 21/10/2019. | |
// Copyright © 2019 MAC. All rights reserved. | |
// | |
import SwiftUI | |
import Combine |
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
// | |
// UnidirectionalCore.swift | |
// UnidirectionalCore | |
// | |
// Created by Fernando Ortiz on 05/05/2019. | |
// Copyright © 2019 Fernando Ortiz. 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
GetAllUsers().execute( | |
onSuccess: { (users: [User]) in | |
// Do something with the users. They are already typed! | |
}, | |
onError: { (error: Error) in | |
// Do something with the error. | |
} | |
) |
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
public extension RequestType { | |
public func execute ( | |
dispatcher: NetworkDispatcher = URLSessionNetworkDispatcher.instance, | |
onSuccess: @escaping (ResponseType) -> Void, | |
onError: @escaping (Error) -> Void | |
) { | |
dispatcher.dispatch( | |
request: self.data, | |
onSuccess: { (responseData: Data) in | |
do { |