diff --git a/Source/UIKit/UIBarButtonItem.swift b/Source/UIKit/UIBarButtonItem.swift index f74b3a7..d48b7b3 100644 --- a/Source/UIKit/UIBarButtonItem.swift +++ b/Source/UIKit/UIBarButtonItem.swift @@ -15,7 +15,7 @@ extension UIBarButtonItem { /// overwritten. This also binds the enabled state of the action to the `rex_enabled` /// property on the button. public var rex_action: MutableProperty { - return associatedObject(self, key: &action) { [weak self] _ in + return associatedObject(self, key: &actionKey) { [weak self] _ in let initial = CocoaAction.rex_disabled let property = MutableProperty(initial) @@ -33,4 +33,4 @@ extension UIBarButtonItem { } } -private var action: UInt8 = 0 +private var actionKey: UInt8 = 0 diff --git a/Source/UIKit/UIBarItem.swift b/Source/UIKit/UIBarItem.swift index d474406..76d33a2 100644 --- a/Source/UIKit/UIBarItem.swift +++ b/Source/UIKit/UIBarItem.swift @@ -12,8 +12,8 @@ import UIKit extension UIBarItem { /// Wraps a UIBarItem's `enabled` state in a bindable property. public var rex_enabled: MutableProperty { - return associatedProperty(self, key: &enabled, initial: { [weak self] in self?.enabled ?? true }, setter: { [weak self] in self?.enabled = $0 }) + return associatedProperty(self, key: &enabledKey, initial: { [weak self] in self?.enabled ?? true }, setter: { [weak self] in self?.enabled = $0 }) } } -private var enabled: UInt8 = 0 +private var enabledKey: UInt8 = 0 diff --git a/Source/UIKit/UIButton.swift b/Source/UIKit/UIButton.swift index 7003f98..f8fb2b8 100644 --- a/Source/UIKit/UIButton.swift +++ b/Source/UIKit/UIButton.swift @@ -15,7 +15,7 @@ extension UIButton { /// previous action is removed as a target. This also binds the enabled state of the /// action to the `rex_enabled` property on the button. public var rex_pressed: MutableProperty { - return associatedObject(self, key: &pressed, initial: { [weak self] _ in + return associatedObject(self, key: &pressedKey, initial: { [weak self] _ in let initial = CocoaAction.rex_disabled let property = MutableProperty(initial) @@ -36,9 +36,9 @@ extension UIButton { /// Wraps a button's `title` text in a bindable property. Note that this only applies /// to `UIControlState.Normal`. public var rex_title: MutableProperty { - return rex_valueProperty(&title, { [weak self] in self?.titleForState(.Normal) ?? "" }, { [weak self] in self?.setTitle($0, forState: .Normal) }) + return rex_valueProperty(&titleKey, { [weak self] in self?.titleForState(.Normal) ?? "" }, { [weak self] in self?.setTitle($0, forState: .Normal) }) } } -private var pressed: UInt8 = 0 -private var title: UInt8 = 0 +private var pressedKey: UInt8 = 0 +private var titleKey: UInt8 = 0 diff --git a/Source/UIKit/UIControl.swift b/Source/UIKit/UIControl.swift index 33b44eb..7e30ec8 100644 --- a/Source/UIKit/UIControl.swift +++ b/Source/UIKit/UIControl.swift @@ -20,20 +20,20 @@ extension UIControl { /// Wraps a control's `enabled` state in a bindable property. public var rex_enabled: MutableProperty { - return rex_valueProperty(&enabled, { [weak self] in self?.enabled ?? true }, { [weak self] in self?.enabled = $0 }) + return rex_valueProperty(&enabledKey, { [weak self] in self?.enabled ?? true }, { [weak self] in self?.enabled = $0 }) } /// Wraps a control's `selected` state in a bindable property. public var rex_selected: MutableProperty { - return rex_valueProperty(&selected, { [weak self] in self?.selected ?? false }, { [weak self] in self?.selected = $0 }) + return rex_valueProperty(&selectedKey, { [weak self] in self?.selected ?? false }, { [weak self] in self?.selected = $0 }) } /// Wraps a control's `highlighted` state in a bindable property. public var rex_highlighted: MutableProperty { - return rex_valueProperty(&highlighted, { [weak self] in self?.highlighted ?? false }, { [weak self] in self?.highlighted = $0 }) + return rex_valueProperty(&highlightedKey, { [weak self] in self?.highlighted ?? false }, { [weak self] in self?.highlighted = $0 }) } } -private var enabled: UInt8 = 0 -private var selected: UInt8 = 0 -private var highlighted: UInt8 = 0 +private var enabledKey: UInt8 = 0 +private var selectedKey: UInt8 = 0 +private var highlightedKey: UInt8 = 0 diff --git a/Source/UIKit/UIImageView.swift b/Source/UIKit/UIImageView.swift index e522c01..dfc41d6 100644 --- a/Source/UIKit/UIImageView.swift +++ b/Source/UIKit/UIImageView.swift @@ -12,14 +12,14 @@ import UIKit extension UIImageView { /// Wraps a imageView's `image` value in a bindable property. public var rex_image: MutableProperty { - return rex_valueProperty(&image, { [weak self] in self?.image }, { [weak self] in self?.image = $0 }) + return rex_valueProperty(&imageKey, { [weak self] in self?.image }, { [weak self] in self?.image = $0 }) } /// Wraps a imageView's `highlightedImage` value in a bindable property. public var rex_highlightedImage: MutableProperty { - return rex_valueProperty(&highlightedImage, { [weak self] in self?.highlightedImage }, { [weak self] in self?.highlightedImage = $0 }) + return rex_valueProperty(&highlightedImageKey, { [weak self] in self?.highlightedImage }, { [weak self] in self?.highlightedImage = $0 }) } } -private var image: UInt8 = 0 -private var highlightedImage: UInt8 = 0 \ No newline at end of file +private var imageKey: UInt8 = 0 +private var highlightedImageKey: UInt8 = 0 \ No newline at end of file diff --git a/Source/UIKit/UIView.swift b/Source/UIKit/UIView.swift index 8532310..1ce1548 100644 --- a/Source/UIKit/UIView.swift +++ b/Source/UIKit/UIView.swift @@ -12,14 +12,14 @@ import UIKit extension UIView { /// Wraps a view's `alpha` value in a bindable property. public var rex_alpha: MutableProperty { - return rex_valueProperty(&alpha, { [weak self] in self?.alpha ?? 1.0 }, { [weak self] in self?.alpha = $0 }) + return rex_valueProperty(&alphaKey, { [weak self] in self?.alpha ?? 1.0 }, { [weak self] in self?.alpha = $0 }) } /// Wraps a view's `hidden` state in a bindable property. public var rex_hidden: MutableProperty { - return rex_valueProperty(&hidden, { [weak self] in self?.hidden ?? false }, { [weak self] in self?.hidden = $0 }) + return rex_valueProperty(&hiddenKey, { [weak self] in self?.hidden ?? false }, { [weak self] in self?.hidden = $0 }) } } -private var alpha: UInt8 = 0 -private var hidden: UInt8 = 0 \ No newline at end of file +private var alphaKey: UInt8 = 0 +private var hiddenKey: UInt8 = 0 \ No newline at end of file diff --git a/Tests/UIKit/UIControlTests.swift b/Tests/UIKit/UIControlTests.swift index b6eb474..d25bd11 100644 --- a/Tests/UIKit/UIControlTests.swift +++ b/Tests/UIKit/UIControlTests.swift @@ -81,4 +81,26 @@ class UIControlTests: XCTestCase { observer.sendNext(false) XCTAssertFalse(control.highlighted) } + + func testEnabledAndSelectedProperty() { + let control = UIControl(frame: CGRectZero) + control.selected = false + control.enabled = false + + let (pipeSignalSelected, observerSelected) = Signal.pipe() + let (pipeSignalEnabled, observerEnabled) = Signal.pipe() + control.rex_selected <~ SignalProducer(signal: pipeSignalSelected) + control.rex_enabled <~ SignalProducer(signal: pipeSignalEnabled) + + observerSelected.sendNext(true) + observerEnabled.sendNext(true) + XCTAssertTrue(control.enabled) + XCTAssertTrue(control.selected) + observerSelected.sendNext(false) + XCTAssertTrue(control.enabled) + XCTAssertFalse(control.selected) + observerEnabled.sendNext(false) + XCTAssertFalse(control.enabled) + XCTAssertFalse(control.selected) + } }