Skip to content

Commit

Permalink
Changed rex_text bindable property to be an optional string (#133)
Browse files Browse the repository at this point in the history
* Changed `rex_text` bindable property to be an optional string

Fixes #125, #129.

* Updated UILabel's text property test to include nullability
  • Loading branch information
dmcrodrigues authored and RuiAAPeres committed Jul 5, 2016
1 parent 265e8e9 commit 0a1927d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Source/UIKit/UILabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import UIKit

extension UILabel {
/// Wraps a label's `text` value in a bindable property.
public var rex_text: MutableProperty<String> {
return associatedProperty(self, keyPath: "text")
public var rex_text: MutableProperty<String?> {
return associatedProperty(self, key: &attributedTextKey, initial: { $0.text }, setter: { $0.text = $1 })
}

/// Wraps a label's `attributedText` value in a bindable property.
Expand All @@ -26,5 +26,6 @@ extension UILabel {
}
}

private var textKey: UInt8 = 0
private var attributedTextKey: UInt8 = 0
private var textColorKey: UInt8 = 0
4 changes: 3 additions & 1 deletion Tests/UIKit/UILabelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ class UILabelTests: XCTestCase {
let label = UILabel(frame: CGRectZero)
label.text = ""

let (pipeSignal, observer) = Signal<String, NoError>.pipe()
let (pipeSignal, observer) = Signal<String?, NoError>.pipe()
label.rex_text <~ SignalProducer(signal: pipeSignal)

observer.sendNext(firstChange)
XCTAssertEqual(label.text, firstChange)
observer.sendNext(secondChange)
XCTAssertEqual(label.text, secondChange)
observer.sendNext(nil)
XCTAssertNil(label.text)
}

func testAttributedTextPropertyDoesntCreateRetainCycle() {
Expand Down
1 change: 1 addition & 0 deletions Tests/UIKit/UITableViewCellTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class UITableViewCellTests: XCTestCase {
label.rex_text <~
titleProperty
.producer
.map(Optional.init) // TODO: Remove in the future, binding with optionals will be available soon in RAC 5. Reference: https://github.com/ReactiveCocoa/ReactiveCocoa/pull/2852
.takeUntil(cell.rex_prepareForReuse)

XCTAssertEqual(label.text, "John")
Expand Down

0 comments on commit 0a1927d

Please sign in to comment.