diff --git a/RxCocoa/RxCocoa.xcodeproj/project.pbxproj b/RxCocoa/RxCocoa.xcodeproj/project.pbxproj index f56dec5a..da8843a0 100644 --- a/RxCocoa/RxCocoa.xcodeproj/project.pbxproj +++ b/RxCocoa/RxCocoa.xcodeproj/project.pbxproj @@ -36,6 +36,7 @@ C88BB8EF1B07F2BE0064D411 /* UITextField+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = C88BB8E71B07F2BE0064D411 /* UITextField+Rx.swift */; }; C88BB91D1B07FD960064D411 /* NSButton+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = C88BB91B1B07FD830064D411 /* NSButton+Rx.swift */; }; C8A56BCE1AD744FD00B4673B /* RxSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C8A56BCD1AD744FD00B4673B /* RxSwift.framework */; }; + CBEEA67A1B12364200176529 /* NSSlider+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBEEA6781B12323800176529 /* NSSlider+Rx.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -49,8 +50,8 @@ C8633AAB1B093EDF00375D60 /* KVOObservable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KVOObservable.swift; sourceTree = ""; }; C8633AAC1B093EDF00375D60 /* Logging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logging.swift; sourceTree = ""; }; C8633AAD1B093EDF00375D60 /* NSNotificationCenter+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSNotificationCenter+Rx.swift"; sourceTree = ""; }; - C8633AAE1B093EDF00375D60 /* NSURLSession+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = "NSURLSession+Rx.swift"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; - C8633AAF1B093EDF00375D60 /* RxCocoa.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = RxCocoa.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + C8633AAE1B093EDF00375D60 /* NSURLSession+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = "NSURLSession+Rx.swift"; sourceTree = ""; }; + C8633AAF1B093EDF00375D60 /* RxCocoa.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = RxCocoa.swift; sourceTree = ""; }; C88BB88D1B07E6130064D411 /* RxCocoa.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RxCocoa.framework; sourceTree = BUILT_PRODUCTS_DIR; }; C88BB8E01B07F2BE0064D411 /* UIButton+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIButton+Rx.swift"; sourceTree = ""; }; C88BB8E11B07F2BE0064D411 /* UICollectionView+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UICollectionView+Rx.swift"; sourceTree = ""; }; @@ -62,6 +63,7 @@ C88BB8E71B07F2BE0064D411 /* UITextField+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UITextField+Rx.swift"; sourceTree = ""; }; C88BB91B1B07FD830064D411 /* NSButton+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSButton+Rx.swift"; sourceTree = ""; }; C8A56BCD1AD744FD00B4673B /* RxSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = RxSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + CBEEA6781B12323800176529 /* NSSlider+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSSlider+Rx.swift"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -164,6 +166,7 @@ C88BB8DF1B07F2190064D411 /* OSX */ = { isa = PBXGroup; children = ( + CBEEA6781B12323800176529 /* NSSlider+Rx.swift */, C88BB91B1B07FD830064D411 /* NSButton+Rx.swift */, C8633A991B08FEBB00375D60 /* NSImageView+Rx.swift */, C8633A971B08FD0600375D60 /* NSTextField+Rx.swift */, @@ -311,6 +314,7 @@ C8633AB11B093EDF00375D60 /* ControlTarget.swift in Sources */, C8633A9A1B08FEBB00375D60 /* NSImageView+Rx.swift in Sources */, C8633AB91B093EDF00375D60 /* NSURLSession+Rx.swift in Sources */, + CBEEA67A1B12364200176529 /* NSSlider+Rx.swift in Sources */, C8633AB71B093EDF00375D60 /* NSNotificationCenter+Rx.swift in Sources */, C8633AB31B093EDF00375D60 /* KVOObservable.swift in Sources */, ); diff --git a/RxCocoa/RxCocoa/OSX/NSSlider+Rx.swift b/RxCocoa/RxCocoa/OSX/NSSlider+Rx.swift new file mode 100644 index 00000000..74551950 --- /dev/null +++ b/RxCocoa/RxCocoa/OSX/NSSlider+Rx.swift @@ -0,0 +1,27 @@ +// +// NSControl+Rx.swift +// RxCocoa +// +// Created by Junior B. on 24/05/15. +// Copyright (c) 2015 Krunoslav Zaher. All rights reserved. +// + +import Foundation +import RxSwift +import Cocoa + +extension NSSlider { + public func rx_value() -> Observable { + return AnonymousObservable { observer in + MainScheduler.ensureExecutingOnScheduler() + + sendNext(observer, self.doubleValue) + + let observer = ControlTarget(control: self) { control in + sendNext(observer, self.doubleValue) + } + + return observer + } + } +} \ No newline at end of file diff --git a/RxExample/RxExample/Example.swift b/RxExample/RxExample/Example.swift index dbb44fed..d1b785ad 100644 --- a/RxExample/RxExample/Example.swift +++ b/RxExample/RxExample/Example.swift @@ -20,9 +20,14 @@ import Foundation let MB = 1024 * 1024 extension String { - func toFloat() -> Float? { - return (self as NSString).floatValue + let numberFormatter = NSNumberFormatter() + return numberFormatter.numberFromString(self)?.floatValue + } + + func toDouble() -> Double? { + let numberFormatter = NSNumberFormatter() + return numberFormatter.numberFromString(self)?.doubleValue } } diff --git a/RxExample/RxExample/Examples/Introduction/IntroductionExampleViewController.swift b/RxExample/RxExample/Examples/Introduction/IntroductionExampleViewController.swift index 64deaa3d..db0f8c14 100644 --- a/RxExample/RxExample/Examples/Introduction/IntroductionExampleViewController.swift +++ b/RxExample/RxExample/Examples/Introduction/IntroductionExampleViewController.swift @@ -16,6 +16,8 @@ class IntroductionExampleViewController : ViewController { @IBOutlet var a: NSTextField! @IBOutlet var b: NSTextField! @IBOutlet var c: NSTextField! + @IBOutlet var slider: NSSlider! + @IBOutlet var sliderValue: NSTextField! @IBOutlet var disposeButton: NSButton! @@ -53,6 +55,21 @@ class IntroductionExampleViewController : ViewController { } >- disposeBag.addDisposable + + slider.rx_value() + >- subscribeNext { value in + self.sliderValue.stringValue = "\(Int(value))" + } + >- disposeBag.addDisposable + + sliderValue.rx_text() + >- subscribeNext { value in + let doubleValue = value.toDouble() ?? 0.0 + self.slider.doubleValue = doubleValue + self.sliderValue.stringValue = "\(Int(doubleValue))" + } + >- disposeBag.addDisposable + disposeButton.rx_tap() >- subscribeNext { [unowned self] _ in println("Unbound everything") diff --git a/RxExample/RxExample/OSX/Main.storyboard b/RxExample/RxExample/OSX/Main.storyboard index 292a7b69..d082dd26 100644 --- a/RxExample/RxExample/OSX/Main.storyboard +++ b/RxExample/RxExample/OSX/Main.storyboard @@ -128,20 +128,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -153,6 +184,8 @@ + +