     
     override func viewDidLoad() {
         super.viewDidLoad()
-        
-    }
-
-    override func viewWillAppear(_ animated: Bool) {
-        super.viewWillAppear(animated)
-    }
-
-    override func didReceiveMemoryWarning() {
-        super.didReceiveMemoryWarning()
-        // Dispose of any resources that can be recreated.
     }
     
     // MARK: - UI Actions

import RxSwift
import RxAlamofire

class MasterViewController: UIViewController, UITextFieldDelegate {
    
    let sourceStringURL = "http://api.fixer.io/latest?base=EUR&symbols=USD"
    let disposeBag = DisposeBag()
    
    @IBOutlet weak var fromTextField: UITextField!
    @IBOutlet weak var toTextField: UITextField!

    @IBAction func convertPressed(_ sender: UIButton) {
        fromTextField.resignFirstResponder()
        
        guard let fromText = self.fromTextField.text, let fromValue = Double(fromText) else {
            self.displayError(APIError.invalidInput.toNSError())
            return
        }
        
        RxAlamofire.requestJSON(.get, exchangeRateEndpoint)
            .debug()
            .flatMap { (_, json) -> Observable<Double> in
                guard
                    let body = json as? [String: Any],
                    let rates = body["rates"] as? [String: Any],
                    let rate = rates["USD"] as? Double
                else {
                    return .error(APIError.badResposne.toNSError())
                }
                return .just(rate)
            }
            .subscribe(onNext: { [weak self] (rate) in
                self?.toTextField.text = "\(rate * fromValue)"
            }, onError: { [weak self] e in
                self?.displayError(e as NSError)
            })
            .disposed(by: self.disposeBag)
    }


