Repository: ReactiveX/RxSwift
File: RxExample/RxExample/Examples/GitHubSignup/Views/GitHubSignupViewController.swift (Swift)

Code before:
    
    @IBOutlet weak var passwordOutlet: UITextField!
    @IBOutlet weak var passwordValidationOutlet: UILabel!
    
    @IBOutlet weak var repeatedPasswordOutlet: UITextField!
    @IBOutlet weak var repeatedPasswordValidationOutlet: UILabel!
    
    @IBOutlet weak var signupOutlet: UIButton!
    @IBOutlet weak var signingUpOulet: UIActivityIndicatorView!
    
    var disposeBag = DisposeBag()
    
    let API = GitHubAPI(
        dataScheduler: MainScheduler.sharedInstance,
        URLSession: NSURLSession.sharedSession()
    )
    
    func bindValidationResultToUI(source: Observable<(valid: Bool?, message: String?)>,
        validationErrorLabel: UILabel) {
        source
            .subscribeNext { v in
                let validationColor: UIColor
                
                if let valid = v.valid {
                    validationColor = valid ? okColor : errorColor
                }
                else {
                   validationColor = UIColor.grayColor()
                }
                
                validationErrorLabel.textColor = validationColor
                validationErrorLabel.text = v.message ?? ""
            }
            .addDisposableTo(disposeBag)
    }
    
    func dismissKeyboard(gr: UITapGestureRecognizer) {
        view.endEditing(true)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tapBackground = UITapGestureRecognizer(target: self, action: Selector("dismissKeyboard:"))
        tapBackground.numberOfTouchesRequired = 1
        view.addGestureRecognizer(tapBackground)
        
        self.disposeBag = DisposeBag()
        
        let API = self.API
        

Review comment (suggestion):
We dispose all subscriptions on `willMoveToParentViewController`, so it's not a leak so far, my bad :)


Code after:
    
    @IBOutlet weak var repeatedPasswordOutlet: UITextField!
    @IBOutlet weak var repeatedPasswordValidationOutlet: UILabel!
    
    @IBOutlet weak var signupOutlet: UIButton!
    @IBOutlet weak var signingUpOulet: UIActivityIndicatorView!
    
    let okColor = UIColor(red: 138.0 / 255.0, green: 221.0 / 255.0, blue: 109.0 / 255.0, alpha: 1.0)
    let errorColor = UIColor.redColor()
    
    var disposeBag = DisposeBag()
    
    let API = GitHubAPI(
        dataScheduler: MainScheduler.sharedInstance,
        URLSession: NSURLSession.sharedSession()
    )
    
    func bindValidationResultToUI(source: Observable<(valid: Bool?, message: String?)>,
        validationErrorLabel: UILabel) {
        source
            .subscribeNext { v in
                let validationColor: UIColor
                
                if let valid = v.valid {
                    validationColor = valid ? self.okColor : self.errorColor
                } else {
                   validationColor = UIColor.grayColor()
                }
                
                validationErrorLabel.textColor = validationColor
                validationErrorLabel.text = v.message ?? ""
            }
            .addDisposableTo(disposeBag)
    }
    
    func dismissKeyboard(gr: UITapGestureRecognizer) {
        view.endEditing(true)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tapBackground = UITapGestureRecognizer(target: self, action: Selector("dismissKeyboard:"))
        view.addGestureRecognizer(tapBackground)
        
        self.disposeBag = DisposeBag()
        
        let API = self.API
        
        let validationService = ValidationService(API: API)