Support for UISearchBar selectedScopeButtonIndex

This commit is contained in:
Stephen H. Gerstacker 2016-02-27 14:06:20 -05:00
parent 396b1a1498
commit 74dd160d56
1 changed files with 21 additions and 0 deletions

View File

@ -47,6 +47,27 @@ extension UISearchBar {
return ControlProperty(values: source, valueSink: bindingObserver)
}
/**
Reactive wrapper for `selectedScopeButtonIndex` property.
*/
public var rx_selectedScopeButtonIndex: ControlProperty<Int> {
let source: Observable<Int> = Observable.deferred { [weak self] () -> Observable<Int> in
let index = self?.selectedScopeButtonIndex ?? 0
return (self?.rx_delegate.observe("searchBar:selectedScopeButtonIndexDidChange:") ?? Observable.empty())
.map { a in
return try castOrThrow(Int.self, a[1])
}
.startWith(index)
}
let bindingObserver = UIBindingObserver(UIElement: self) { (searchBar, index: Int) in
searchBar.selectedScopeButtonIndex = index
}
return ControlProperty(values: source, valueSink: bindingObserver)
}
}
#endif