diff --git a/RxCocoa/OSX/NSButton+Rx.swift b/RxCocoa/OSX/NSButton+Rx.swift index 460baef2..0c6e5f6c 100644 --- a/RxCocoa/OSX/NSButton+Rx.swift +++ b/RxCocoa/OSX/NSButton+Rx.swift @@ -20,4 +20,15 @@ extension NSButton { public var rx_tap: ControlEvent { return rx_controlEvent } + + /** + Reactive wrapper for `state` property`. + */ + public var rx_state: ControlProperty { + return rx_value(getter: { [weak self] in + return self?.state ?? 0 + }, setter: { [weak self] state in + self?.state = state + }) + } } \ No newline at end of file diff --git a/Tests/RxCocoaTests/Control+RxTests+Cocoa.swift b/Tests/RxCocoaTests/Control+RxTests+Cocoa.swift index a81fd3d3..90555276 100644 --- a/Tests/RxCocoaTests/Control+RxTests+Cocoa.swift +++ b/Tests/RxCocoaTests/Control+RxTests+Cocoa.swift @@ -41,4 +41,9 @@ extension ControlTests { let createView: () -> NSButton = { NSButton(frame: CGRectMake(0, 0, 1, 1)) } ensureEventDeallocated(createView) { (view: NSButton) in view.rx_tap } } + + func testButton_StateCompletesOnDealloc() { + let createView: () -> NSButton = { NSButton(frame: CGRectMake(0, 0, 1, 1)) } + ensureEventDeallocated(createView) { (view: NSButton) in view.rx_state } + } } \ No newline at end of file