├── .gitignore ├── LICENSE ├── PhoneNumberTextField.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcshareddata │ └── xcschemes │ └── PhoneNumberTextField.xcscheme ├── PhoneNumberTextField ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Formatting │ ├── PhoneNumber.swift │ ├── PhoneNumberFormatStyle.swift │ └── PhoneNumberParseStrategy.swift ├── PhoneNumberTextFieldApp.swift ├── Preview Content │ └── Preview Assets.xcassets │ │ └── Contents.json └── Views │ ├── ContentView.swift │ └── PhoneNumberTextField.swift ├── PhoneNumberTextFieldTests └── PhoneNumberFormatStyleTests.swift └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | ## Playgrounds 32 | timeline.xctimeline 33 | playground.xcworkspace 34 | 35 | # Swift Package Manager 36 | # 37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 38 | # Packages/ 39 | # Package.pins 40 | # Package.resolved 41 | .build/ 42 | 43 | # CocoaPods 44 | # 45 | # We recommend against adding the Pods directory to your .gitignore. However 46 | # you should judge for yourself, the pros and cons are mentioned at: 47 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 48 | # 49 | # Pods/ 50 | # 51 | # Add this line if you want to avoid checking in source code from the Xcode workspace 52 | # *.xcworkspace 53 | 54 | # Carthage 55 | # 56 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 57 | # Carthage/Checkouts 58 | 59 | Carthage/Build 60 | 61 | # fastlane 62 | # 63 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 64 | # screenshots whenever they are needed. 65 | # For more information about the recommended setup visit: 66 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 67 | 68 | fastlane/report.xml 69 | fastlane/Preview.html 70 | fastlane/screenshots/**/*.png 71 | fastlane/test_output 72 | 73 | # Code Injection 74 | # 75 | # After new code Injection tools there's a generated folder /iOSInjectionProject 76 | # https://github.com/johnno1962/injectionforxcode 77 | 78 | iOSInjectionProject/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 emptyfuel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /PhoneNumberTextField.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 55; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 4D4EB90B26C69E4000162AAB /* PhoneNumber.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D4EB90A26C69E4000162AAB /* PhoneNumber.swift */; }; 11 | 4D4EB90D26C6A26500162AAB /* PhoneNumberFormatStyleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D4EB90C26C6A26500162AAB /* PhoneNumberFormatStyleTests.swift */; }; 12 | 4D4EB91526C80A7600162AAB /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 4D4EB91426C80A7600162AAB /* README.md */; }; 13 | 4DB079DB26B594840061495B /* PhoneNumberTextFieldApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DB079DA26B594840061495B /* PhoneNumberTextFieldApp.swift */; }; 14 | 4DB079DD26B594840061495B /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DB079DC26B594840061495B /* ContentView.swift */; }; 15 | 4DB079DF26B594850061495B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4DB079DE26B594850061495B /* Assets.xcassets */; }; 16 | 4DB079E226B594850061495B /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4DB079E126B594850061495B /* Preview Assets.xcassets */; }; 17 | 4DB079E926B597010061495B /* PhoneNumberTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DB079E826B597010061495B /* PhoneNumberTextField.swift */; }; 18 | 4DB079EB26B59BF30061495B /* PhoneNumberFormatStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DB079EA26B59BF30061495B /* PhoneNumberFormatStyle.swift */; }; 19 | 4DB079ED26B59C690061495B /* PhoneNumberParseStrategy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DB079EC26B59C690061495B /* PhoneNumberParseStrategy.swift */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXContainerItemProxy section */ 23 | 4DB079F626C157440061495B /* PBXContainerItemProxy */ = { 24 | isa = PBXContainerItemProxy; 25 | containerPortal = 4DB079CF26B594840061495B /* Project object */; 26 | proxyType = 1; 27 | remoteGlobalIDString = 4DB079D626B594840061495B; 28 | remoteInfo = PhoneNumberTextField; 29 | }; 30 | /* End PBXContainerItemProxy section */ 31 | 32 | /* Begin PBXFileReference section */ 33 | 4D4EB90A26C69E4000162AAB /* PhoneNumber.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhoneNumber.swift; sourceTree = ""; }; 34 | 4D4EB90C26C6A26500162AAB /* PhoneNumberFormatStyleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhoneNumberFormatStyleTests.swift; sourceTree = ""; }; 35 | 4D4EB91426C80A7600162AAB /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 36 | 4DB079D726B594840061495B /* PhoneNumberTextField.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PhoneNumberTextField.app; sourceTree = BUILT_PRODUCTS_DIR; }; 37 | 4DB079DA26B594840061495B /* PhoneNumberTextFieldApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhoneNumberTextFieldApp.swift; sourceTree = ""; }; 38 | 4DB079DC26B594840061495B /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 39 | 4DB079DE26B594850061495B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 40 | 4DB079E126B594850061495B /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 41 | 4DB079E826B597010061495B /* PhoneNumberTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhoneNumberTextField.swift; sourceTree = ""; }; 42 | 4DB079EA26B59BF30061495B /* PhoneNumberFormatStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhoneNumberFormatStyle.swift; sourceTree = ""; }; 43 | 4DB079EC26B59C690061495B /* PhoneNumberParseStrategy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhoneNumberParseStrategy.swift; sourceTree = ""; }; 44 | 4DB079F226C157440061495B /* PhoneNumberTextFieldTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PhoneNumberTextFieldTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 45 | /* End PBXFileReference section */ 46 | 47 | /* Begin PBXFrameworksBuildPhase section */ 48 | 4DB079D426B594840061495B /* Frameworks */ = { 49 | isa = PBXFrameworksBuildPhase; 50 | buildActionMask = 2147483647; 51 | files = ( 52 | ); 53 | runOnlyForDeploymentPostprocessing = 0; 54 | }; 55 | 4DB079EF26C157440061495B /* Frameworks */ = { 56 | isa = PBXFrameworksBuildPhase; 57 | buildActionMask = 2147483647; 58 | files = ( 59 | ); 60 | runOnlyForDeploymentPostprocessing = 0; 61 | }; 62 | /* End PBXFrameworksBuildPhase section */ 63 | 64 | /* Begin PBXGroup section */ 65 | 4D4EB91226C6BF8200162AAB /* Views */ = { 66 | isa = PBXGroup; 67 | children = ( 68 | 4DB079DC26B594840061495B /* ContentView.swift */, 69 | 4DB079E826B597010061495B /* PhoneNumberTextField.swift */, 70 | ); 71 | path = Views; 72 | sourceTree = ""; 73 | }; 74 | 4D4EB91326C6BFC000162AAB /* Formatting */ = { 75 | isa = PBXGroup; 76 | children = ( 77 | 4D4EB90A26C69E4000162AAB /* PhoneNumber.swift */, 78 | 4DB079EA26B59BF30061495B /* PhoneNumberFormatStyle.swift */, 79 | 4DB079EC26B59C690061495B /* PhoneNumberParseStrategy.swift */, 80 | ); 81 | path = Formatting; 82 | sourceTree = ""; 83 | }; 84 | 4DB079CE26B594840061495B = { 85 | isa = PBXGroup; 86 | children = ( 87 | 4D4EB91426C80A7600162AAB /* README.md */, 88 | 4DB079D926B594840061495B /* PhoneNumberTextField */, 89 | 4DB079F326C157440061495B /* PhoneNumberTextFieldTests */, 90 | 4DB079D826B594840061495B /* Products */, 91 | ); 92 | sourceTree = ""; 93 | }; 94 | 4DB079D826B594840061495B /* Products */ = { 95 | isa = PBXGroup; 96 | children = ( 97 | 4DB079D726B594840061495B /* PhoneNumberTextField.app */, 98 | 4DB079F226C157440061495B /* PhoneNumberTextFieldTests.xctest */, 99 | ); 100 | name = Products; 101 | sourceTree = ""; 102 | }; 103 | 4DB079D926B594840061495B /* PhoneNumberTextField */ = { 104 | isa = PBXGroup; 105 | children = ( 106 | 4DB079DA26B594840061495B /* PhoneNumberTextFieldApp.swift */, 107 | 4D4EB91326C6BFC000162AAB /* Formatting */, 108 | 4DB079E026B594850061495B /* Preview Content */, 109 | 4D4EB91226C6BF8200162AAB /* Views */, 110 | 4DB079DE26B594850061495B /* Assets.xcassets */, 111 | ); 112 | path = PhoneNumberTextField; 113 | sourceTree = ""; 114 | }; 115 | 4DB079E026B594850061495B /* Preview Content */ = { 116 | isa = PBXGroup; 117 | children = ( 118 | 4DB079E126B594850061495B /* Preview Assets.xcassets */, 119 | ); 120 | path = "Preview Content"; 121 | sourceTree = ""; 122 | }; 123 | 4DB079F326C157440061495B /* PhoneNumberTextFieldTests */ = { 124 | isa = PBXGroup; 125 | children = ( 126 | 4D4EB90C26C6A26500162AAB /* PhoneNumberFormatStyleTests.swift */, 127 | ); 128 | path = PhoneNumberTextFieldTests; 129 | sourceTree = ""; 130 | }; 131 | /* End PBXGroup section */ 132 | 133 | /* Begin PBXNativeTarget section */ 134 | 4DB079D626B594840061495B /* PhoneNumberTextField */ = { 135 | isa = PBXNativeTarget; 136 | buildConfigurationList = 4DB079E526B594850061495B /* Build configuration list for PBXNativeTarget "PhoneNumberTextField" */; 137 | buildPhases = ( 138 | 4DB079D326B594840061495B /* Sources */, 139 | 4DB079D426B594840061495B /* Frameworks */, 140 | 4DB079D526B594840061495B /* Resources */, 141 | ); 142 | buildRules = ( 143 | ); 144 | dependencies = ( 145 | ); 146 | name = PhoneNumberTextField; 147 | productName = PhoneNumberTextField; 148 | productReference = 4DB079D726B594840061495B /* PhoneNumberTextField.app */; 149 | productType = "com.apple.product-type.application"; 150 | }; 151 | 4DB079F126C157440061495B /* PhoneNumberTextFieldTests */ = { 152 | isa = PBXNativeTarget; 153 | buildConfigurationList = 4DB079F826C157440061495B /* Build configuration list for PBXNativeTarget "PhoneNumberTextFieldTests" */; 154 | buildPhases = ( 155 | 4DB079EE26C157440061495B /* Sources */, 156 | 4DB079EF26C157440061495B /* Frameworks */, 157 | 4DB079F026C157440061495B /* Resources */, 158 | ); 159 | buildRules = ( 160 | ); 161 | dependencies = ( 162 | 4DB079F726C157440061495B /* PBXTargetDependency */, 163 | ); 164 | name = PhoneNumberTextFieldTests; 165 | productName = PhoneNumberTextFieldTests; 166 | productReference = 4DB079F226C157440061495B /* PhoneNumberTextFieldTests.xctest */; 167 | productType = "com.apple.product-type.bundle.unit-test"; 168 | }; 169 | /* End PBXNativeTarget section */ 170 | 171 | /* Begin PBXProject section */ 172 | 4DB079CF26B594840061495B /* Project object */ = { 173 | isa = PBXProject; 174 | attributes = { 175 | BuildIndependentTargetsInParallel = 1; 176 | LastSwiftUpdateCheck = 1300; 177 | LastUpgradeCheck = 1300; 178 | TargetAttributes = { 179 | 4DB079D626B594840061495B = { 180 | CreatedOnToolsVersion = 13.0; 181 | }; 182 | 4DB079F126C157440061495B = { 183 | CreatedOnToolsVersion = 13.0; 184 | TestTargetID = 4DB079D626B594840061495B; 185 | }; 186 | }; 187 | }; 188 | buildConfigurationList = 4DB079D226B594840061495B /* Build configuration list for PBXProject "PhoneNumberTextField" */; 189 | compatibilityVersion = "Xcode 13.0"; 190 | developmentRegion = en; 191 | hasScannedForEncodings = 0; 192 | knownRegions = ( 193 | en, 194 | Base, 195 | ); 196 | mainGroup = 4DB079CE26B594840061495B; 197 | productRefGroup = 4DB079D826B594840061495B /* Products */; 198 | projectDirPath = ""; 199 | projectRoot = ""; 200 | targets = ( 201 | 4DB079D626B594840061495B /* PhoneNumberTextField */, 202 | 4DB079F126C157440061495B /* PhoneNumberTextFieldTests */, 203 | ); 204 | }; 205 | /* End PBXProject section */ 206 | 207 | /* Begin PBXResourcesBuildPhase section */ 208 | 4DB079D526B594840061495B /* Resources */ = { 209 | isa = PBXResourcesBuildPhase; 210 | buildActionMask = 2147483647; 211 | files = ( 212 | 4D4EB91526C80A7600162AAB /* README.md in Resources */, 213 | 4DB079E226B594850061495B /* Preview Assets.xcassets in Resources */, 214 | 4DB079DF26B594850061495B /* Assets.xcassets in Resources */, 215 | ); 216 | runOnlyForDeploymentPostprocessing = 0; 217 | }; 218 | 4DB079F026C157440061495B /* Resources */ = { 219 | isa = PBXResourcesBuildPhase; 220 | buildActionMask = 2147483647; 221 | files = ( 222 | ); 223 | runOnlyForDeploymentPostprocessing = 0; 224 | }; 225 | /* End PBXResourcesBuildPhase section */ 226 | 227 | /* Begin PBXSourcesBuildPhase section */ 228 | 4DB079D326B594840061495B /* Sources */ = { 229 | isa = PBXSourcesBuildPhase; 230 | buildActionMask = 2147483647; 231 | files = ( 232 | 4DB079EB26B59BF30061495B /* PhoneNumberFormatStyle.swift in Sources */, 233 | 4DB079DD26B594840061495B /* ContentView.swift in Sources */, 234 | 4DB079DB26B594840061495B /* PhoneNumberTextFieldApp.swift in Sources */, 235 | 4DB079ED26B59C690061495B /* PhoneNumberParseStrategy.swift in Sources */, 236 | 4DB079E926B597010061495B /* PhoneNumberTextField.swift in Sources */, 237 | 4D4EB90B26C69E4000162AAB /* PhoneNumber.swift in Sources */, 238 | ); 239 | runOnlyForDeploymentPostprocessing = 0; 240 | }; 241 | 4DB079EE26C157440061495B /* Sources */ = { 242 | isa = PBXSourcesBuildPhase; 243 | buildActionMask = 2147483647; 244 | files = ( 245 | 4D4EB90D26C6A26500162AAB /* PhoneNumberFormatStyleTests.swift in Sources */, 246 | ); 247 | runOnlyForDeploymentPostprocessing = 0; 248 | }; 249 | /* End PBXSourcesBuildPhase section */ 250 | 251 | /* Begin PBXTargetDependency section */ 252 | 4DB079F726C157440061495B /* PBXTargetDependency */ = { 253 | isa = PBXTargetDependency; 254 | target = 4DB079D626B594840061495B /* PhoneNumberTextField */; 255 | targetProxy = 4DB079F626C157440061495B /* PBXContainerItemProxy */; 256 | }; 257 | /* End PBXTargetDependency section */ 258 | 259 | /* Begin XCBuildConfiguration section */ 260 | 4DB079E326B594850061495B /* Debug */ = { 261 | isa = XCBuildConfiguration; 262 | buildSettings = { 263 | ALWAYS_SEARCH_USER_PATHS = NO; 264 | CLANG_ANALYZER_NONNULL = YES; 265 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 266 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 267 | CLANG_CXX_LIBRARY = "libc++"; 268 | CLANG_ENABLE_MODULES = YES; 269 | CLANG_ENABLE_OBJC_ARC = YES; 270 | CLANG_ENABLE_OBJC_WEAK = YES; 271 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 272 | CLANG_WARN_BOOL_CONVERSION = YES; 273 | CLANG_WARN_COMMA = YES; 274 | CLANG_WARN_CONSTANT_CONVERSION = YES; 275 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 276 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 277 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 278 | CLANG_WARN_EMPTY_BODY = YES; 279 | CLANG_WARN_ENUM_CONVERSION = YES; 280 | CLANG_WARN_INFINITE_RECURSION = YES; 281 | CLANG_WARN_INT_CONVERSION = YES; 282 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 283 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 284 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 285 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 286 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 287 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 288 | CLANG_WARN_STRICT_PROTOTYPES = YES; 289 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 290 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 291 | CLANG_WARN_UNREACHABLE_CODE = YES; 292 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 293 | COPY_PHASE_STRIP = NO; 294 | DEBUG_INFORMATION_FORMAT = dwarf; 295 | ENABLE_STRICT_OBJC_MSGSEND = YES; 296 | ENABLE_TESTABILITY = YES; 297 | GCC_C_LANGUAGE_STANDARD = gnu11; 298 | GCC_DYNAMIC_NO_PIC = NO; 299 | GCC_NO_COMMON_BLOCKS = YES; 300 | GCC_OPTIMIZATION_LEVEL = 0; 301 | GCC_PREPROCESSOR_DEFINITIONS = ( 302 | "DEBUG=1", 303 | "$(inherited)", 304 | ); 305 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 306 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 307 | GCC_WARN_UNDECLARED_SELECTOR = YES; 308 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 309 | GCC_WARN_UNUSED_FUNCTION = YES; 310 | GCC_WARN_UNUSED_VARIABLE = YES; 311 | IPHONEOS_DEPLOYMENT_TARGET = 15.0; 312 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 313 | MTL_FAST_MATH = YES; 314 | ONLY_ACTIVE_ARCH = YES; 315 | SDKROOT = iphoneos; 316 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 317 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 318 | }; 319 | name = Debug; 320 | }; 321 | 4DB079E426B594850061495B /* Release */ = { 322 | isa = XCBuildConfiguration; 323 | buildSettings = { 324 | ALWAYS_SEARCH_USER_PATHS = NO; 325 | CLANG_ANALYZER_NONNULL = YES; 326 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 327 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 328 | CLANG_CXX_LIBRARY = "libc++"; 329 | CLANG_ENABLE_MODULES = YES; 330 | CLANG_ENABLE_OBJC_ARC = YES; 331 | CLANG_ENABLE_OBJC_WEAK = YES; 332 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 333 | CLANG_WARN_BOOL_CONVERSION = YES; 334 | CLANG_WARN_COMMA = YES; 335 | CLANG_WARN_CONSTANT_CONVERSION = YES; 336 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 337 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 338 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 339 | CLANG_WARN_EMPTY_BODY = YES; 340 | CLANG_WARN_ENUM_CONVERSION = YES; 341 | CLANG_WARN_INFINITE_RECURSION = YES; 342 | CLANG_WARN_INT_CONVERSION = YES; 343 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 344 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 345 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 346 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 347 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 348 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 349 | CLANG_WARN_STRICT_PROTOTYPES = YES; 350 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 351 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 352 | CLANG_WARN_UNREACHABLE_CODE = YES; 353 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 354 | COPY_PHASE_STRIP = NO; 355 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 356 | ENABLE_NS_ASSERTIONS = NO; 357 | ENABLE_STRICT_OBJC_MSGSEND = YES; 358 | GCC_C_LANGUAGE_STANDARD = gnu11; 359 | GCC_NO_COMMON_BLOCKS = YES; 360 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 361 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 362 | GCC_WARN_UNDECLARED_SELECTOR = YES; 363 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 364 | GCC_WARN_UNUSED_FUNCTION = YES; 365 | GCC_WARN_UNUSED_VARIABLE = YES; 366 | IPHONEOS_DEPLOYMENT_TARGET = 15.0; 367 | MTL_ENABLE_DEBUG_INFO = NO; 368 | MTL_FAST_MATH = YES; 369 | SDKROOT = iphoneos; 370 | SWIFT_COMPILATION_MODE = wholemodule; 371 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 372 | VALIDATE_PRODUCT = YES; 373 | }; 374 | name = Release; 375 | }; 376 | 4DB079E626B594850061495B /* Debug */ = { 377 | isa = XCBuildConfiguration; 378 | buildSettings = { 379 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 380 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 381 | CODE_SIGN_STYLE = Automatic; 382 | CURRENT_PROJECT_VERSION = 1; 383 | DEVELOPMENT_ASSET_PATHS = "\"PhoneNumberTextField/Preview Content\""; 384 | DEVELOPMENT_TEAM = ""; 385 | ENABLE_PREVIEWS = YES; 386 | GENERATE_INFOPLIST_FILE = YES; 387 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 388 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 389 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 390 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 391 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 392 | IPHONEOS_DEPLOYMENT_TARGET = 15.0; 393 | LD_RUNPATH_SEARCH_PATHS = ( 394 | "$(inherited)", 395 | "@executable_path/Frameworks", 396 | ); 397 | MARKETING_VERSION = 1.0; 398 | PRODUCT_BUNDLE_IDENTIFIER = com.emptytheory.PhoneNumberTextField; 399 | PRODUCT_NAME = "$(TARGET_NAME)"; 400 | SWIFT_EMIT_LOC_STRINGS = YES; 401 | SWIFT_VERSION = 5.0; 402 | TARGETED_DEVICE_FAMILY = "1,2"; 403 | }; 404 | name = Debug; 405 | }; 406 | 4DB079E726B594850061495B /* Release */ = { 407 | isa = XCBuildConfiguration; 408 | buildSettings = { 409 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 410 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 411 | CODE_SIGN_STYLE = Automatic; 412 | CURRENT_PROJECT_VERSION = 1; 413 | DEVELOPMENT_ASSET_PATHS = "\"PhoneNumberTextField/Preview Content\""; 414 | DEVELOPMENT_TEAM = ""; 415 | ENABLE_PREVIEWS = YES; 416 | GENERATE_INFOPLIST_FILE = YES; 417 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 418 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 419 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 420 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 421 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 422 | IPHONEOS_DEPLOYMENT_TARGET = 15.0; 423 | LD_RUNPATH_SEARCH_PATHS = ( 424 | "$(inherited)", 425 | "@executable_path/Frameworks", 426 | ); 427 | MARKETING_VERSION = 1.0; 428 | PRODUCT_BUNDLE_IDENTIFIER = com.emptytheory.PhoneNumberTextField; 429 | PRODUCT_NAME = "$(TARGET_NAME)"; 430 | SWIFT_EMIT_LOC_STRINGS = YES; 431 | SWIFT_VERSION = 5.0; 432 | TARGETED_DEVICE_FAMILY = "1,2"; 433 | }; 434 | name = Release; 435 | }; 436 | 4DB079F926C157440061495B /* Debug */ = { 437 | isa = XCBuildConfiguration; 438 | buildSettings = { 439 | BUNDLE_LOADER = "$(TEST_HOST)"; 440 | CODE_SIGN_IDENTITY = "Apple Development"; 441 | "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; 442 | CODE_SIGN_STYLE = Automatic; 443 | CURRENT_PROJECT_VERSION = 1; 444 | DEVELOPMENT_TEAM = ""; 445 | GENERATE_INFOPLIST_FILE = YES; 446 | LD_RUNPATH_SEARCH_PATHS = ( 447 | "$(inherited)", 448 | "@executable_path/Frameworks", 449 | "@loader_path/Frameworks", 450 | ); 451 | MARKETING_VERSION = 1.0; 452 | PRODUCT_BUNDLE_IDENTIFIER = com.emptytheory.PhoneNumberTextFieldTests; 453 | PRODUCT_NAME = "$(TARGET_NAME)"; 454 | PROVISIONING_PROFILE_SPECIFIER = ""; 455 | "PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = ""; 456 | SWIFT_EMIT_LOC_STRINGS = NO; 457 | SWIFT_VERSION = 5.0; 458 | TARGETED_DEVICE_FAMILY = "1,2"; 459 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PhoneNumberTextField.app/PhoneNumberTextField"; 460 | }; 461 | name = Debug; 462 | }; 463 | 4DB079FA26C157440061495B /* Release */ = { 464 | isa = XCBuildConfiguration; 465 | buildSettings = { 466 | BUNDLE_LOADER = "$(TEST_HOST)"; 467 | CODE_SIGN_IDENTITY = "Apple Development"; 468 | "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; 469 | CODE_SIGN_STYLE = Automatic; 470 | CURRENT_PROJECT_VERSION = 1; 471 | DEVELOPMENT_TEAM = ""; 472 | GENERATE_INFOPLIST_FILE = YES; 473 | LD_RUNPATH_SEARCH_PATHS = ( 474 | "$(inherited)", 475 | "@executable_path/Frameworks", 476 | "@loader_path/Frameworks", 477 | ); 478 | MARKETING_VERSION = 1.0; 479 | PRODUCT_BUNDLE_IDENTIFIER = com.emptytheory.PhoneNumberTextFieldTests; 480 | PRODUCT_NAME = "$(TARGET_NAME)"; 481 | PROVISIONING_PROFILE_SPECIFIER = ""; 482 | "PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = ""; 483 | SWIFT_EMIT_LOC_STRINGS = NO; 484 | SWIFT_VERSION = 5.0; 485 | TARGETED_DEVICE_FAMILY = "1,2"; 486 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PhoneNumberTextField.app/PhoneNumberTextField"; 487 | }; 488 | name = Release; 489 | }; 490 | /* End XCBuildConfiguration section */ 491 | 492 | /* Begin XCConfigurationList section */ 493 | 4DB079D226B594840061495B /* Build configuration list for PBXProject "PhoneNumberTextField" */ = { 494 | isa = XCConfigurationList; 495 | buildConfigurations = ( 496 | 4DB079E326B594850061495B /* Debug */, 497 | 4DB079E426B594850061495B /* Release */, 498 | ); 499 | defaultConfigurationIsVisible = 0; 500 | defaultConfigurationName = Release; 501 | }; 502 | 4DB079E526B594850061495B /* Build configuration list for PBXNativeTarget "PhoneNumberTextField" */ = { 503 | isa = XCConfigurationList; 504 | buildConfigurations = ( 505 | 4DB079E626B594850061495B /* Debug */, 506 | 4DB079E726B594850061495B /* Release */, 507 | ); 508 | defaultConfigurationIsVisible = 0; 509 | defaultConfigurationName = Release; 510 | }; 511 | 4DB079F826C157440061495B /* Build configuration list for PBXNativeTarget "PhoneNumberTextFieldTests" */ = { 512 | isa = XCConfigurationList; 513 | buildConfigurations = ( 514 | 4DB079F926C157440061495B /* Debug */, 515 | 4DB079FA26C157440061495B /* Release */, 516 | ); 517 | defaultConfigurationIsVisible = 0; 518 | defaultConfigurationName = Release; 519 | }; 520 | /* End XCConfigurationList section */ 521 | }; 522 | rootObject = 4DB079CF26B594840061495B /* Project object */; 523 | } 524 | -------------------------------------------------------------------------------- /PhoneNumberTextField.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /PhoneNumberTextField.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /PhoneNumberTextField.xcodeproj/xcshareddata/xcschemes/PhoneNumberTextField.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 53 | 55 | 61 | 62 | 63 | 64 | 70 | 72 | 78 | 79 | 80 | 81 | 83 | 84 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /PhoneNumberTextField/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /PhoneNumberTextField/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /PhoneNumberTextField/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /PhoneNumberTextField/Formatting/PhoneNumber.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PhoneNumber.swift 3 | // PhoneNumber 4 | // 5 | // Created by Mark Thormann on 8/13/21. 6 | // 7 | 8 | import Foundation 9 | 10 | /// Representation of U.S. phone number 11 | public struct PhoneNumber { 12 | 13 | /// Area code 14 | public var areaCode: String 15 | 16 | /// First three digits of a 7-digit phone number 17 | public var exchange: String 18 | 19 | /// Last four digits of a 7-digit phone number 20 | public var number: String 21 | 22 | /// Constructor 23 | /// - Parameters: 24 | /// - areaCode: Area code 25 | /// - exchange: First three digits of a 7-digit phone number 26 | /// - number: Last four digits of a 7-digit phone number 27 | public init(areaCode: String, exchange: String, number: String) { 28 | self.areaCode = areaCode 29 | self.exchange = exchange 30 | self.number = number 31 | } 32 | 33 | } 34 | 35 | public extension PhoneNumber { 36 | 37 | /// Get a formatted string from a format style 38 | /// - Parameter formatStyle: Phone number format style 39 | /// - Returns: Formatted string 40 | func formatted(_ formatStyle: PhoneNumberFormatStyle) -> String { 41 | formatStyle.format(self) 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /PhoneNumberTextField/Formatting/PhoneNumberFormatStyle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PhoneNumberFormatStyle.swift 3 | // PhoneNumberFormatStyle 4 | // 5 | // Created by Mark Thormann on 7/31/21. 6 | // 7 | 8 | import Foundation 9 | 10 | public extension FormatStyle where Self == PhoneNumber.PhoneNumberFormatStyle { 11 | 12 | /// Format the given string as a phone number in the format (___) ___-____ or similar 13 | static var phoneNumber: PhoneNumber.PhoneNumberFormatStyle { 14 | PhoneNumber.PhoneNumberFormatStyle() 15 | } 16 | 17 | } 18 | 19 | //MARK: - Object phone number 20 | 21 | public extension PhoneNumber { 22 | 23 | /// Phone number formatting style 24 | struct PhoneNumberFormatStyle { 25 | 26 | /// Pieces of the phone number 27 | enum PhoneNumberFormatStyleType: CaseIterable, Codable { 28 | case parentheses // Include the parentheses around the area code 29 | case hyphen // Include the hyphen in the middle of the phone number 30 | case space // Include the space between area code and phone number 31 | case areaCode // Area code 32 | case phoneNumber // Phone number itself 33 | } 34 | 35 | /// Type of formatting 36 | var formatStyleTypes: [PhoneNumberFormatStyleType] = [] 37 | 38 | /// Placeholder character 39 | var placeholder: Character = "_" 40 | 41 | /// Constructor w/placeholder optional 42 | /// - Parameter placeholder: Placeholder to use instead of '_' 43 | init(placeholder: Character = "_") { 44 | self.placeholder = placeholder 45 | } 46 | 47 | /// Constructer to allow extensions to set formatting 48 | /// - Parameter formatStyleTypes: Format style types 49 | init(_ formatStyleTypes: [PhoneNumberFormatStyleType]) { 50 | self.formatStyleTypes = formatStyleTypes 51 | } 52 | } 53 | 54 | } 55 | 56 | extension PhoneNumber.PhoneNumberFormatStyle: ParseableFormatStyle { 57 | 58 | /// A `ParseStrategy` that can be used to parse this `FormatStyle`'s output 59 | public var parseStrategy: PhoneNumberParseStrategy { 60 | return PhoneNumberParseStrategy() 61 | } 62 | 63 | public func format(_ value: PhoneNumber) -> String { 64 | 65 | // Fill out fields with placeholder 66 | let stringPlaceholder = String(placeholder) 67 | let paddedAreaCode = value.areaCode.padding(toLength: 3, withPad: stringPlaceholder, startingAt: 0) 68 | let paddedExchange = value.exchange.padding(toLength: 3, withPad: stringPlaceholder, startingAt: 0) 69 | let paddedNumber = value.number.padding(toLength: 4, withPad: stringPlaceholder, startingAt: 0) 70 | 71 | // Get the working style types 72 | let workingStyleTypes = !formatStyleTypes.isEmpty ? formatStyleTypes : PhoneNumberFormatStyleType.allCases 73 | 74 | var output = "" 75 | if workingStyleTypes.contains(.areaCode) { 76 | output += workingStyleTypes.contains(.parentheses) ? "(" + paddedAreaCode + ")" : paddedAreaCode 77 | } 78 | if workingStyleTypes.contains(.space) && workingStyleTypes.contains(.areaCode) && workingStyleTypes.contains(.phoneNumber) { 79 | // Without the area code and phone number, no point with space 80 | output += " " 81 | } 82 | if workingStyleTypes.contains(.phoneNumber) { 83 | output += workingStyleTypes.contains(.hyphen) ? paddedExchange + "-" + paddedNumber : paddedExchange + paddedNumber 84 | } 85 | 86 | // All done 87 | return output 88 | } 89 | 90 | } 91 | 92 | extension PhoneNumber.PhoneNumberFormatStyle: Codable { 93 | 94 | enum CodingKeys: String, CodingKey { 95 | case formatStyleTypes 96 | case placeholder 97 | } 98 | 99 | public init(from decoder: Decoder) throws { 100 | let container = try decoder.container(keyedBy: CodingKeys.self) 101 | if let newTypes = try? container.decodeIfPresent([PhoneNumberFormatStyleType].self, forKey: .formatStyleTypes) { 102 | formatStyleTypes = newTypes 103 | } 104 | if let newPlaceHolder = try? container.decodeIfPresent(String.self, forKey: .placeholder), let characterPlaceholder = newPlaceHolder.first { 105 | placeholder = characterPlaceholder 106 | } 107 | } 108 | 109 | public func encode(to encoder: Encoder) throws { 110 | var container = encoder.container(keyedBy: CodingKeys.self) 111 | try container.encode(formatStyleTypes, forKey: .formatStyleTypes) 112 | try container.encode(String(placeholder), forKey: .placeholder) 113 | } 114 | 115 | } 116 | 117 | /// Publicly available format styles to allow fluent build of the style 118 | public extension PhoneNumber.PhoneNumberFormatStyle { 119 | 120 | /// Return just the area code (e.g. 617) 121 | /// - Returns: Format style 122 | func areaCode() -> PhoneNumber.PhoneNumberFormatStyle { 123 | return getNewFormatStyle(for: .areaCode) 124 | } 125 | 126 | /// Return just the phone number (e.g. 555-1212) 127 | /// - Returns: Format style 128 | func number() -> PhoneNumber.PhoneNumberFormatStyle { 129 | return getNewFormatStyle(for: .phoneNumber) 130 | } 131 | 132 | /// Return the space between the area code and phone number 133 | /// - Returns: Format style 134 | func space() -> PhoneNumber.PhoneNumberFormatStyle { 135 | return getNewFormatStyle(for: .space) 136 | } 137 | 138 | /// Return the parentheses around the area code 139 | /// - Returns: Format style 140 | func parentheses() -> PhoneNumber.PhoneNumberFormatStyle { 141 | return getNewFormatStyle(for: .parentheses) 142 | } 143 | 144 | /// Return the hyphen in the middle of the phone number 145 | /// - Returns: Format style 146 | func hyphen() -> PhoneNumber.PhoneNumberFormatStyle { 147 | return getNewFormatStyle(for: .hyphen) 148 | } 149 | 150 | /// Get a new phone number format style 151 | /// - Parameter newType: New type 152 | /// - Returns: Format style 153 | private func getNewFormatStyle(for newType: PhoneNumberFormatStyleType) -> PhoneNumber.PhoneNumberFormatStyle { 154 | if !formatStyleTypes.contains(newType) { 155 | var newTypes = formatStyleTypes 156 | newTypes.append(newType) 157 | return PhoneNumber.PhoneNumberFormatStyle(newTypes) 158 | } 159 | // If the user duplicated the type, just return that type 160 | return self 161 | } 162 | 163 | } 164 | -------------------------------------------------------------------------------- /PhoneNumberTextField/Formatting/PhoneNumberParseStrategy.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PhoneNumberParseStrategy.swift 3 | // PhoneNumberParseStrategy 4 | // 5 | // Created by Mark Thormann on 7/31/21. 6 | // 7 | 8 | import Foundation 9 | 10 | /// Parse strategy for `PhoneNumber` 11 | public struct PhoneNumberParseStrategy: ParseStrategy { 12 | 13 | /// Creates an instance of the `ParseOutput` type from `value`. 14 | /// - Parameter value: Value to convert to `PhoneNumber` object 15 | /// - Returns: `PhoneNumber` object 16 | public func parse(_ value: String) throws -> PhoneNumber { 17 | // Strip out to just numerics. Throw out parentheses, etc. and then convert to an array of characters. Simple version here ignores country codes, localized phone numbers, invalid area codes, etc. 18 | let maxPhoneNumberLength = 10 19 | let numericValue = Array(value.filter({ $0.isWholeNumber }).prefix(maxPhoneNumberLength)) 20 | 21 | // PUll out the phone number components 22 | var areaCode: String = "" 23 | var exchange: String = "" 24 | var number: String = "" 25 | for i in 0..