Adds UILabel rx_attributedText.
This commit is contained in:
parent
018523bf1e
commit
731e69a680
|
|
@ -2,6 +2,7 @@
|
|||
All notable changes to this project will be documented in this file.
|
||||
|
||||
* Adds `ignoreElements` operator.
|
||||
* Adds `rx_attributedText` to `UILabel`.
|
||||
|
||||
---
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,25 @@ extension UILabel {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Bindable sink for `attributedText` property.
|
||||
*/
|
||||
public var rx_attributedText: AnyObserver<NSAttributedString?> {
|
||||
return AnyObserver { [weak self] event in
|
||||
MainScheduler.ensureExecutingOnScheduler()
|
||||
|
||||
switch event {
|
||||
case .Next(let value):
|
||||
self?.attributedText = value
|
||||
case .Error(let error):
|
||||
bindingErrorToInterface(error)
|
||||
break
|
||||
case .Completed:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -154,6 +154,22 @@ extension ControlTests {
|
|||
}
|
||||
}
|
||||
|
||||
// UILabel
|
||||
extension ControlTests {
|
||||
func testLabel_HasWeakReference() {
|
||||
ensureControlObserverHasWeakReference(UILabel(), { (label: UILabel) -> AnyObserver<NSAttributedString?> in label.rx_attributedText }, { Variable<NSAttributedString?>(nil).asObservable() })
|
||||
}
|
||||
|
||||
func testLabel_NextElementsSetsValue() {
|
||||
let subject = UILabel()
|
||||
let attributedTextSequence = Variable<NSAttributedString?>(nil)
|
||||
|
||||
attributedTextSequence.subscribe(subject.rx_attributedText)
|
||||
|
||||
attributedTextSequence.value = NSAttributedString(string: "Hello!")
|
||||
XCTAssert(subject.attributedText == attributedTextSequence.value, "Expected attributedText to have been set")
|
||||
}
|
||||
}
|
||||
|
||||
// UITableView
|
||||
extension ControlTests {
|
||||
|
|
|
|||
|
|
@ -78,4 +78,24 @@ class ControlTests : RxTest {
|
|||
XCTAssertTrue(deallocated)
|
||||
XCTAssertTrue(completed)
|
||||
}
|
||||
|
||||
func ensureControlObserverHasWeakReference<C, T where C: NSObject>(@autoclosure createControl: () -> (C), _ observerSelector: C -> AnyObserver<T>, _ observableSelector: () -> (Observable<T>)) {
|
||||
var deallocated = false
|
||||
|
||||
let disposeBag = DisposeBag()
|
||||
|
||||
autoreleasepool {
|
||||
let control = createControl()
|
||||
let propertyObserver = observerSelector(control)
|
||||
let observable = observableSelector()
|
||||
|
||||
observable.bindTo(propertyObserver).addDisposableTo(disposeBag)
|
||||
|
||||
_ = control.rx_deallocated.subscribeNext { _ in
|
||||
deallocated = true
|
||||
}
|
||||
}
|
||||
|
||||
XCTAssertTrue(deallocated)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue