Skip to content

Commit 329e67f

Browse files
committed
Create TextFormatter protocol
1 parent 7b79a86 commit 329e67f

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

Example/Example.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
8F0F533B1DC1524A00791173 /* FormattedTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F0F53371DC1524A00791173 /* FormattedTextField.swift */; };
1111
8F0F533E1DC1524A00791173 /* UITextFieldExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F0F533A1DC1524A00791173 /* UITextFieldExtension.swift */; };
12+
8F2C0C7A1DD7C3F700F06656 /* TextFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F2C0C781DD7C3F700F06656 /* TextFormatter.swift */; };
1213
8F93C22B1DC15913007A4101 /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F93C22A1DC15913007A4101 /* StringExtension.swift */; };
1314
8FD40B571DC1366F0015DB1D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8FD40B561DC1366F0015DB1D /* AppDelegate.swift */; };
1415
8FD40B591DC1366F0015DB1D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8FD40B581DC1366F0015DB1D /* ViewController.swift */; };
@@ -20,6 +21,7 @@
2021
/* Begin PBXFileReference section */
2122
8F0F53371DC1524A00791173 /* FormattedTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormattedTextField.swift; sourceTree = "<group>"; };
2223
8F0F533A1DC1524A00791173 /* UITextFieldExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITextFieldExtension.swift; sourceTree = "<group>"; };
24+
8F2C0C781DD7C3F700F06656 /* TextFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextFormatter.swift; sourceTree = "<group>"; };
2325
8F93C22A1DC15913007A4101 /* StringExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = "<group>"; };
2426
8FD40B531DC1366F0015DB1D /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
2527
8FD40B561DC1366F0015DB1D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@@ -44,6 +46,7 @@
4446
8F0F53351DC1524A00791173 /* FormattedTextField */ = {
4547
isa = PBXGroup;
4648
children = (
49+
8F2C0C781DD7C3F700F06656 /* TextFormatter.swift */,
4750
8F93C22A1DC15913007A4101 /* StringExtension.swift */,
4851
8F0F53371DC1524A00791173 /* FormattedTextField.swift */,
4952
8F0F533A1DC1524A00791173 /* UITextFieldExtension.swift */,
@@ -158,6 +161,7 @@
158161
8F0F533B1DC1524A00791173 /* FormattedTextField.swift in Sources */,
159162
8F93C22B1DC15913007A4101 /* StringExtension.swift in Sources */,
160163
8FD40B591DC1366F0015DB1D /* ViewController.swift in Sources */,
164+
8F2C0C7A1DD7C3F700F06656 /* TextFormatter.swift in Sources */,
161165
8FD40B571DC1366F0015DB1D /* AppDelegate.swift in Sources */,
162166
);
163167
runOnlyForDeploymentPostprocessing = 0;

FormattedTextField.xcodeproj/project.pbxproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,30 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
8F9320221DD775890097A8AF /* FormattedTextField.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8FFF61571DBC074D0033E1FC /* FormattedTextField.framework */; };
11+
8F9320291DD7759D0097A8AF /* TextFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F9320281DD7759D0097A8AF /* TextFormatter.swift */; };
1012
8FD40B471DBEB3840015DB1D /* UITextFieldExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8FD40B461DBEB3840015DB1D /* UITextFieldExtension.swift */; };
1113
8FFF615C1DBC074E0033E1FC /* FormattedTextField.h in Headers */ = {isa = PBXBuildFile; fileRef = 8FFF615A1DBC074E0033E1FC /* FormattedTextField.h */; settings = {ATTRIBUTES = (Public, ); }; };
1214
8FFF61641DBC07C70033E1FC /* FormattedTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8FFF61621DBC07C70033E1FC /* FormattedTextField.swift */; };
1315
8FFF61651DBC07C70033E1FC /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8FFF61631DBC07C70033E1FC /* StringExtension.swift */; };
1416
/* End PBXBuildFile section */
1517

18+
/* Begin PBXContainerItemProxy section */
19+
8F9320231DD775890097A8AF /* PBXContainerItemProxy */ = {
20+
isa = PBXContainerItemProxy;
21+
containerPortal = 8FFF614E1DBC074D0033E1FC /* Project object */;
22+
proxyType = 1;
23+
remoteGlobalIDString = 8FFF61561DBC074D0033E1FC;
24+
remoteInfo = FormattedTextField;
25+
};
26+
/* End PBXContainerItemProxy section */
27+
1628
/* Begin PBXFileReference section */
29+
8F93201D1DD775890097A8AF /* FormattedTextFieldTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FormattedTextFieldTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
30+
8F93201F1DD775890097A8AF /* MaskTextFormatterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MaskTextFormatterTests.swift; sourceTree = "<group>"; };
31+
8F9320211DD775890097A8AF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
32+
8F9320281DD7759D0097A8AF /* TextFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextFormatter.swift; sourceTree = "<group>"; };
33+
8F93202A1DD776C30097A8AF /* MaskTextFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaskTextFormatter.swift; sourceTree = "<group>"; };
1734
8FD40B461DBEB3840015DB1D /* UITextFieldExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITextFieldExtension.swift; sourceTree = "<group>"; };
1835
8FFF61571DBC074D0033E1FC /* FormattedTextField.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = FormattedTextField.framework; sourceTree = BUILT_PRODUCTS_DIR; };
1936
8FFF615A1DBC074E0033E1FC /* FormattedTextField.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FormattedTextField.h; sourceTree = "<group>"; };
@@ -57,6 +74,7 @@
5774
8FD40B461DBEB3840015DB1D /* UITextFieldExtension.swift */,
5875
8FFF615A1DBC074E0033E1FC /* FormattedTextField.h */,
5976
8FFF615B1DBC074E0033E1FC /* Info.plist */,
77+
8F9320281DD7759D0097A8AF /* TextFormatter.swift */,
6078
);
6179
path = FormattedTextField;
6280
sourceTree = "<group>";
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// TextFormatter.swift
3+
// FormattedTextField
4+
//
5+
// Created by Evgeniy Yurtaev on 12/11/2016.
6+
// Copyright © 2016 Evgeniy Yurtaev. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public protocol TextFromatter {
12+
func formattedText(from text: String, range: Range<String.Index>) -> (text: String, range: Range<String.Index>)
13+
func unformattedText(from text: String, range: Range<String.Index>) -> (text: String, range: Range<String.Index>)
14+
}
15+
16+
public extension TextFromatter {
17+
public func formattedText(from text: String) -> String {
18+
return formattedText(from: text, range: text.startIndex..<text.startIndex).text
19+
}
20+
21+
public func unformattedText(from text: String) -> String {
22+
return unformattedText(from: text, range: text.startIndex..<text.startIndex).text
23+
}
24+
}

0 commit comments

Comments
 (0)