LoginSignup
1
1

More than 3 years have passed since last update.

RxSwiftのメモ

Last updated at Posted at 2019-07-20

ViewModelからUISearchBarへ値をセット

これでセットすると、UISearchBarからの変更通知がこない?

import RxCocoa

class ViewModel {
    let textOutput: PublishRelay<String?> = PublishRelay<String?>()
}
import UIKit
import RxSwift
import RxCocoa

class ViewController : UIViewController {

    private let vm: ViewModel = ViewModel()

    private let disposeBag: DisposeBag = DisposeBag()

    @IBOutlet private weak var searchBar: UISearchBar! {
        didSet {
            self.vm.textOutput
                .bind(to: self.searchBar.rx.text)
                .disposed(by: self.disposeBag)
        }
    }

}

メソッドの実行を検知する

継承してオーバーライドしなくとも下記のようにしてメソッドの実行を検知できる

let view = UIView()
view.rx.methodInvoked(#selector(UIView.layoutSubviews))
    .subscribe(onNext: { _ in
        // 処理
     })
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1