Latest 1.0.0
License MIT
Platforms ios 10.0, requires ARC
Frameworks UIKit

GPSMaskTextField is a framework for UITextField that helps the development of forms without the developer worrying about the basics of validations that a field needs.

This framework has a validation system using reflection and in a simple and practical way, it is possible to validate all text fields in a ViewController using very little code.


  • iOS 10.0+ / macOS 10.12+ / tvOS 10.0+ / watchOS 3.0+
  • Xcode 10.2+
  • Swift 5+



CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate GPSMaskTextField into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'GPSMaskTextField', '~> 1.0.0'


  • First, you must create a UITextField in Interface Builder.

criando um UITextField

  • Second, just assign the custom class GPSMaskTextField to your UITextField

atribuindo a classe customizada

  • Third, import the GPSMaskTextField and create the IBOutlet:
import GPSMaskTextField

criando o Outlet

@IBOutlet weak var textField: GPSMaskTextField!

This alone is enough for you to use all the basic validation features available in Interface Builder. With the GPSMaskTextField you do not even have to assign the delegate to your ViewController, this is already done automatically.

But if you prefer to implement the UITextField delegate itself, you can do so in the conventional way that automatically becomes a priority in your ViewController.

  • In the Interface Builder we have the following configurations:


  • Custom Mask: Mask to be used as examples:
    1 - (##) #### - ####
    2 - #### %
    3 - #######

    The mask can be a string of characters, spaces, and so on. The # is where the text will be entered by the user.

The best thing about using Custom Mask is that for the convenience of the developer to redeem the value assigned to the UITextField, the GPSMaskTextField has a function, according to the example below, that returns the value entered by the user without the mask, no longer having to do replace for obtaining of this value:

let valueString = textField.getTextWithoutMask()
  • Minimum Size: Minimum of characters required for the field.
  • Maximum Size: Maximum characters required for the field.

If Custom Mask field is filled in these 2 settings will be automatically assigned with the mask size set.

  • Name TextField: Friendly name, used for the validation option of all the fields (treated below), in which returns to the invalid field this friendly name, in case the developer wants to use it for message presentation.

  • Is Currency: A value that determines if the field is of the monetary type, if yes the fields "Main Separator and Decimal Separator" should be filled in. By default, this value is off (false).

  • Main Separator: The character used when the field is of the monetary type, in the thousands, in the "Is Currency".

  • Decimal Separator: The character used when the field is of the monetary type, in the decimal houses, configured in the "Is Currency".

Example of use:



  • Is Required: The configuration that determines whether the fields will be mandatory or not for use in the validation functionality of all fields, as explained below in the "Validating all fields" option.

  • Next To Validate: If "On" enables the field so that, after validation according to its settings made, it passes the focus to the next field, if any. By default, this value is "Off". For this functionality to work properly IBOutlets must be declared in their Controller in the same order as their Interface Builder.

Validating all fields

GPSMaskTextField has a validation class that if instantiated, using reflection, takes care of all the validations configured for the field and notifies its controller if all the fields are valid or not as explained in the section "Delegates of field validation".

To use the automatic validation features, simply invoke the instance of the "ValidationFields ()" class in the viewDidLoad, calling its function "validationAllFields ()", informing which class has the GPSMaskTextField objects to validate in the first parameter and in the second who will implement the delegate with the answers "ValidationFieldsDelegate", according to example below:

The automatic validation only resets the fields that have "Is Required" enabled "On". Fields that have this option "Off" will have their masks applied normally but are not contemplated by this extra validation.

import UIKit
import GPSMaskTextField

class ViewController: UIViewController {

    @IBOutlet weak var textField1: GPSMaskTextField!
    @IBOutlet weak var textField2: GPSMaskTextField!
    @IBOutlet weak var textField3: GPSMaskTextField!

    override func viewDidLoad() {
        ValidationFields().validationAllFields(for: self, delegate: self)
extension ViewController : ValidationFieldsDelegate {
    func allFieldsValid() {
        // All fields are valid

    func notValidAllFields(fildesNotValid: [FieldsValidation]) {
        // Reports all fields that have not yet met your validation

The function parameter "notValidAllFields (fildesNotValid: [FieldsValidation])" is an array of a struct returning information and the object itself GPSMaskTextField:

public struct FieldsValidation {
    var validIsRequired = false // If the field is required
    var name = "" // Friendly name configured in Interface Builder
    var errorValidation: ErrorValidateMask = .none // Enum with type of error in validation
    var textField = GPSMaskTextField() // TextField field object

Field Validation Delegates

To use the automatic validation feature provided by the "ValidationFields" class, your Controller must implement the "ValidationFieldsDelegate" and optionally you can implement the "ValidationActionDelegate" to specifically capture the keyboard display and hiding:

// Required to capture validation events
 public protocol ValidationFieldsDelegate: NSObjectProtocol {
    func allFieldsValid()
    func notValidAllFields(fildesNotValid: [FieldsValidation])

// Optional for capturing keyboard display or hiding
@objc public protocol ValidationActionDelegate: NSObjectProtocol {
    @objc optional func showKeyboard(notification: Notification)
    @objc optional func hideKeyboard(notification: Notification)



First of all, thank God, my family for the support and especially the understanding and for my friends who helped me and supported me from the beginning, especially my friends Tomaz Correa, Vitor Maura, Millfford Bradshaw. Thank you all.


GPSMaskTextField was developed by Gilson Santos ([email protected])

Latest podspec

    "name": "GPSMaskTextField",
    "platforms": {
        "ios": "10.0"
    "summary": "GPSMaskTextField lets a user select an ice cream flavor.",
    "requires_arc": true,
    "version": "1.0.0",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "Gilson Santos": "[email protected]"
    "homepage": "",
    "source": {
        "git": "",
        "tag": "1.0.0"
    "frameworks": "UIKit",
    "source_files": "GPSMaskTextField/**/*.{swift}",
    "swift_versions": "5.0"

Pin It on Pinterest

Share This