From 42435875167de59d530a3df2c153eb34baf601ad Mon Sep 17 00:00:00 2001 From: Markus Chmelar Date: Thu, 12 Nov 2015 12:09:34 +0100 Subject: [PATCH 1/2] add `rex_textColor` to UILabel --- Source/UIKit/UILabel.swift | 4 ++++ Tests/UIKit/UILabelTests.swift | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/Source/UIKit/UILabel.swift b/Source/UIKit/UILabel.swift index d353f5e..719c22a 100644 --- a/Source/UIKit/UILabel.swift +++ b/Source/UIKit/UILabel.swift @@ -14,4 +14,8 @@ extension UILabel { public var rex_text: MutableProperty { return rex_stringProperty("text") } + + public var rex_textColor: MutableProperty { + return rex_valueProperty(&textColor, { [weak self] in (self?.textColor)! }, { [weak self] in self?.textColor = $0 }) + } } diff --git a/Tests/UIKit/UILabelTests.swift b/Tests/UIKit/UILabelTests.swift index e365e28..24c64c4 100644 --- a/Tests/UIKit/UILabelTests.swift +++ b/Tests/UIKit/UILabelTests.swift @@ -42,4 +42,20 @@ class UILabelTests: XCTestCase { observer.sendNext(secondChange) XCTAssertEqual(label.text, secondChange) } + + func testTextColorProperty() { + let firstChange = UIColor.redColor() + let secondChange = UIColor.blackColor() + + let label = UILabel(frame: CGRectZero) + + let (pipeSignal, observer) = Signal.pipe() + label.textColor = UIColor.blackColor() + label.rex_textColor <~ SignalProducer(signal: pipeSignal) + + observer.sendNext(firstChange) + XCTAssertEqual(label.textColor, firstChange) + observer.sendNext(secondChange) + XCTAssertEqual(label.textColor, secondChange) + } } From a071507afbd4814b5e54ca826094e2a0db9d4d98 Mon Sep 17 00:00:00 2001 From: Markus Chmelar Date: Sun, 22 Nov 2015 13:44:05 +0100 Subject: [PATCH 2/2] Use the default color of a new UILabel as fallback instead of force unwrapping --- Source/UIKit/UILabel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/UIKit/UILabel.swift b/Source/UIKit/UILabel.swift index 719c22a..c999eec 100644 --- a/Source/UIKit/UILabel.swift +++ b/Source/UIKit/UILabel.swift @@ -16,6 +16,6 @@ extension UILabel { } public var rex_textColor: MutableProperty { - return rex_valueProperty(&textColor, { [weak self] in (self?.textColor)! }, { [weak self] in self?.textColor = $0 }) + return rex_valueProperty(&textColor, { [weak self] in self?.textColor ?? UILabel().textColor }, { [weak self] in self?.textColor = $0 }) } }