commit
ea1ae3ae86
|
|
@ -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 = "<group>"; };
|
||||
C8633AAC1B093EDF00375D60 /* Logging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logging.swift; sourceTree = "<group>"; };
|
||||
C8633AAD1B093EDF00375D60 /* NSNotificationCenter+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSNotificationCenter+Rx.swift"; sourceTree = "<group>"; };
|
||||
C8633AAE1B093EDF00375D60 /* NSURLSession+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = "NSURLSession+Rx.swift"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
|
||||
C8633AAF1B093EDF00375D60 /* RxCocoa.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = RxCocoa.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
|
||||
C8633AAE1B093EDF00375D60 /* NSURLSession+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = "NSURLSession+Rx.swift"; sourceTree = "<group>"; };
|
||||
C8633AAF1B093EDF00375D60 /* RxCocoa.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = RxCocoa.swift; sourceTree = "<group>"; };
|
||||
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 = "<group>"; };
|
||||
C88BB8E11B07F2BE0064D411 /* UICollectionView+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UICollectionView+Rx.swift"; sourceTree = "<group>"; };
|
||||
|
|
@ -62,6 +63,7 @@
|
|||
C88BB8E71B07F2BE0064D411 /* UITextField+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UITextField+Rx.swift"; sourceTree = "<group>"; };
|
||||
C88BB91B1B07FD830064D411 /* NSButton+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSButton+Rx.swift"; sourceTree = "<group>"; };
|
||||
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 = "<group>"; };
|
||||
/* 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 */,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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<Double> {
|
||||
return AnonymousObservable { observer in
|
||||
MainScheduler.ensureExecutingOnScheduler()
|
||||
|
||||
sendNext(observer, self.doubleValue)
|
||||
|
||||
let observer = ControlTarget(control: self) { control in
|
||||
sendNext(observer, self.doubleValue)
|
||||
}
|
||||
|
||||
return observer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -128,20 +128,51 @@
|
|||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<slider verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Wbs-Vv-RvG">
|
||||
<rect key="frame" x="54" y="156" width="502" height="21"/>
|
||||
<sliderCell key="cell" continuous="YES" state="on" alignment="left" maxValue="100" doubleValue="50" tickMarkPosition="above" sliderType="linear" id="0FL-dG-a0V"/>
|
||||
</slider>
|
||||
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="35N-M1-mEj">
|
||||
<rect key="frame" x="208" y="122" width="96" height="22"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="96" id="UjJ-QN-7sX"/>
|
||||
<constraint firstAttribute="height" constant="22" id="p0d-PC-IYH"/>
|
||||
</constraints>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" title="1" drawsBackground="YES" id="Gej-gH-W9B">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="uJU-xc-Cnn">
|
||||
<rect key="frame" x="56" y="125" width="136" height="17"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Slider Value (0 - 100):" id="Pbz-ZR-CzF">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="zhP-9C-de5" firstAttribute="centerY" secondItem="Thn-ge-MNK" secondAttribute="centerY" id="1hB-vb-8wU"/>
|
||||
<constraint firstAttribute="centerY" secondItem="6lb-zc-c5S" secondAttribute="centerY" constant="126.5" id="3Es-uc-xme"/>
|
||||
<constraint firstItem="zEm-ia-8D5" firstAttribute="leading" secondItem="6lb-zc-c5S" secondAttribute="trailing" constant="44" id="4YD-Sv-3PW"/>
|
||||
<constraint firstItem="zhP-9C-de5" firstAttribute="centerY" secondItem="zEm-ia-8D5" secondAttribute="centerY" id="6x6-ry-73f"/>
|
||||
<constraint firstAttribute="trailing" secondItem="Wbs-Vv-RvG" secondAttribute="trailing" constant="56" id="PVJ-9U-aoZ"/>
|
||||
<constraint firstItem="uvp-P6-I33" firstAttribute="top" secondItem="GIP-PK-nj4" secondAttribute="bottom" constant="14" id="Pp9-qm-Arb"/>
|
||||
<constraint firstItem="6lb-zc-c5S" firstAttribute="leading" secondItem="15P-I4-Ofm" secondAttribute="leading" constant="56" id="PvR-bi-zxk"/>
|
||||
<constraint firstItem="35N-M1-mEj" firstAttribute="top" secondItem="Wbs-Vv-RvG" secondAttribute="bottom" constant="14" id="XjL-NS-FKB"/>
|
||||
<constraint firstItem="6lb-zc-c5S" firstAttribute="centerY" secondItem="zEm-ia-8D5" secondAttribute="centerY" constant="0.5" id="Yxd-Vc-Mha"/>
|
||||
<constraint firstItem="uJU-xc-Cnn" firstAttribute="top" secondItem="Wbs-Vv-RvG" secondAttribute="bottom" constant="16" id="aTW-iC-ZJu"/>
|
||||
<constraint firstItem="2kf-g2-Xe7" firstAttribute="leading" secondItem="15P-I4-Ofm" secondAttribute="leading" constant="58" id="aUY-dz-Bkn"/>
|
||||
<constraint firstItem="OPN-Cj-AXY" firstAttribute="centerY" secondItem="Thn-ge-MNK" secondAttribute="centerY" id="cze-3D-fjj"/>
|
||||
<constraint firstItem="2kf-g2-Xe7" firstAttribute="top" secondItem="15P-I4-Ofm" secondAttribute="top" constant="9" id="dVJ-tS-uK5"/>
|
||||
<constraint firstItem="Wbs-Vv-RvG" firstAttribute="top" secondItem="uvp-P6-I33" secondAttribute="bottom" constant="53" id="gJ8-k4-cPu"/>
|
||||
<constraint firstItem="GIP-PK-nj4" firstAttribute="top" secondItem="zhP-9C-de5" secondAttribute="bottom" constant="38" id="hP1-SO-AwZ"/>
|
||||
<constraint firstItem="zhP-9C-de5" firstAttribute="centerX" secondItem="GIP-PK-nj4" secondAttribute="centerX" id="jGy-4g-Az3"/>
|
||||
<constraint firstItem="Wbs-Vv-RvG" firstAttribute="leading" secondItem="15P-I4-Ofm" secondAttribute="leading" constant="56" id="oZe-4i-rFT"/>
|
||||
<constraint firstItem="uJU-xc-Cnn" firstAttribute="leading" secondItem="15P-I4-Ofm" secondAttribute="leading" constant="58" id="qNL-oi-8XY"/>
|
||||
<constraint firstItem="35N-M1-mEj" firstAttribute="leading" secondItem="uJU-xc-Cnn" secondAttribute="trailing" constant="18" id="rna-lY-yUb"/>
|
||||
<constraint firstItem="Thn-ge-MNK" firstAttribute="leading" secondItem="zhP-9C-de5" secondAttribute="trailing" constant="44" id="s0C-Xr-olp"/>
|
||||
<constraint firstItem="OPN-Cj-AXY" firstAttribute="leading" secondItem="Thn-ge-MNK" secondAttribute="trailing" constant="44" id="wsy-fG-oAX"/>
|
||||
<constraint firstItem="uvp-P6-I33" firstAttribute="centerX" secondItem="GIP-PK-nj4" secondAttribute="centerX" id="y3H-7u-VYu"/>
|
||||
|
|
@ -153,6 +184,8 @@
|
|||
<outlet property="b" destination="zhP-9C-de5" id="roc-0E-LNn"/>
|
||||
<outlet property="c" destination="OPN-Cj-AXY" id="QWI-hj-WBi"/>
|
||||
<outlet property="disposeButton" destination="GIP-PK-nj4" id="GRz-GM-yYC"/>
|
||||
<outlet property="slider" destination="Wbs-Vv-RvG" id="P4j-BE-GM4"/>
|
||||
<outlet property="sliderValue" destination="35N-M1-mEj" id="sJI-D2-QJ8"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<customObject id="Q2y-PY-QrU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
|
||||
|
|
|
|||
Loading…
Reference in New Issue