Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added UITextView text's producer #95

Merged
merged 2 commits into from
Apr 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Rex.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
C7932E831C4B3F3000086F3C /* UITextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7932E811C4B3EDB00086F3C /* UITextField.swift */; };
C7932E841C4B41E100086F3C /* UITextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7932E811C4B3EDB00086F3C /* UITextField.swift */; };
C7932E871C4B42F500086F3C /* UITextFieldTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7932E851C4B420A00086F3C /* UITextFieldTests.swift */; };
C7DCE2B41CB3C89A001217D8 /* UITextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7DCE2B21CB3C872001217D8 /* UITextView.swift */; };
C7DCE2B71CB3C9D6001217D8 /* UITextViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7DCE2B51CB3C9C1001217D8 /* UITextViewTests.swift */; };
D8003E941AFEC3D400D7D3C5 /* Rex.h in Headers */ = {isa = PBXBuildFile; fileRef = D8003E931AFEC3D400D7D3C5 /* Rex.h */; settings = {ATTRIBUTES = (Public, ); }; };
D8003EB41AFEC6B000D7D3C5 /* ReactiveCocoa.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = D8003EAD1AFEC68A00D7D3C5 /* ReactiveCocoa.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
D8003EB51AFEC6B000D7D3C5 /* Result.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = D8003EAE1AFEC68A00D7D3C5 /* Result.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand Down Expand Up @@ -184,6 +186,8 @@
9DA915A51CA63046003723B9 /* UIDatePickerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIDatePickerTests.swift; sourceTree = "<group>"; };
C7932E811C4B3EDB00086F3C /* UITextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITextField.swift; sourceTree = "<group>"; };
C7932E851C4B420A00086F3C /* UITextFieldTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITextFieldTests.swift; sourceTree = "<group>"; };
C7DCE2B21CB3C872001217D8 /* UITextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITextView.swift; sourceTree = "<group>"; };
C7DCE2B51CB3C9C1001217D8 /* UITextViewTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITextViewTests.swift; sourceTree = "<group>"; };
D8003E921AFEC3D400D7D3C5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
D8003E931AFEC3D400D7D3C5 /* Rex.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Rex.h; sourceTree = "<group>"; };
D8003E9F1AFEC3D400D7D3C5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -394,6 +398,7 @@
8289A2E21BD7EF740097FB60 /* UIImageView.swift */,
D86FFBD71B34B242001A89B3 /* UILabel.swift */,
C7932E811C4B3EDB00086F3C /* UITextField.swift */,
C7DCE2B21CB3C872001217D8 /* UITextView.swift */,
8289A2E41BD7F6DD0097FB60 /* UIView.swift */,
);
path = UIKit;
Expand Down Expand Up @@ -430,6 +435,7 @@
8289A2E01BD7EF1F0097FB60 /* UIImageViewTests.swift */,
D8F073141B861B3A0047D546 /* UILabelTests.swift */,
C7932E851C4B420A00086F3C /* UITextFieldTests.swift */,
C7DCE2B51CB3C9C1001217D8 /* UITextViewTests.swift */,
8289A2E61BD7F7730097FB60 /* UIViewTests.swift */,
);
path = UIKit;
Expand Down Expand Up @@ -774,6 +780,7 @@
D8E4A6201B7BBB1600EAD8A8 /* UIBarButtonItem.swift in Sources */,
D8F097451B17F3C8002E15BA /* NSObject.swift in Sources */,
D834572E1AFEE45B0070616A /* SignalProducer.swift in Sources */,
C7DCE2B41CB3C89A001217D8 /* UITextView.swift in Sources */,
8289A2E51BD7F6DD0097FB60 /* UIView.swift in Sources */,
D86FFBD61B34B116001A89B3 /* UIControl.swift in Sources */,
D8F0973F1B17F31E002E15BA /* NSData.swift in Sources */,
Expand All @@ -797,6 +804,7 @@
D83457411AFEE6050070616A /* SignalTests.swift in Sources */,
8295FD8D1B87374A007C9000 /* UIBarButtonItemTests.swift in Sources */,
8295FD871B87309F007C9000 /* UIControlTests.swift in Sources */,
C7DCE2B71CB3C9D6001217D8 /* UITextViewTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
5 changes: 1 addition & 4 deletions Source/UIKit/UITextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ extension UITextField {
public var rex_textSignal: SignalProducer<String, NoError> {
return NSNotificationCenter.defaultCenter()
.rac_notifications(UITextFieldTextDidChangeNotification, object: self)
.filterMap { notification in
guard let textField = notification.object as? UITextField else { return nil}
return textField.text
}
.filterMap { ($0.object as? UITextField)?.text }
}
}
21 changes: 21 additions & 0 deletions Source/UIKit/UITextView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// UITextView.swift
// Rex
//
// Created by Rui Peres on 05/04/2016.
// Copyright © 2016 Neil Pankey. All rights reserved.
//

import ReactiveCocoa
import UIKit
import enum Result.NoError

extension UITextView {

/// Sends the textView's string value whenever it changes.
public var rex_textSignal: SignalProducer<String, NoError> {
return NSNotificationCenter.defaultCenter()
.rac_notifications(UITextViewTextDidChangeNotification, object: self)
.filterMap { ($0.object as? UITextView)?.text }
}
}
29 changes: 29 additions & 0 deletions Tests/UIKit/UITextViewTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// UITextViewTests.swift
// Rex
//
// Created by Rui Peres on 05/04/2016.
// Copyright © 2016 Neil Pankey. All rights reserved.
//

import ReactiveCocoa
import UIKit
import XCTest

class UITextViewTests: XCTestCase {

func testTextProperty() {
let expectation = self.expectationWithDescription("Expected textSignal's value to equal to the textViews's text")
defer { self.waitForExpectationsWithTimeout(2, handler: nil) }

let textView = UITextView(frame: CGRectZero)
textView.text = "Test"

textView.rex_textSignal.startWithNext { text in
XCTAssertEqual(text, textView.text)
expectation.fulfill()
}

NSNotificationCenter.defaultCenter().postNotificationName(UITextViewTextDidChangeNotification, object: textView)
}
}