Skip to content

Quick Start

Egor Taflanidi edited this page Feb 6, 2019 · 4 revisions

Given you have already installed our library, let's get started and put together a small project.

Simple UITextField for phone numbers

Drop an object on your scene and cofigure it as a MaskedTextFieldDelegate:

Interface Builder

Assign your UITextField.delegate to be this object:

Interface Builder

Make sure your ViewController knows its residents:

Interface Builder

open class ViewController: UIViewController {
    @IBOutlet weak var listener: MaskedTextFieldDelegate!
    @IBOutlet weak var field: UITextField! 
}

Check that your object's Primary Mask Format contains a proper mask pattern:

+7 ([000]) [000] [00] [00]

Prepare for receiving text changed events by assigning your ViewController as a delegate to MaskedTextFieldDelegate object:

Interface Builder

Make your ViewController to implement MaskedTextFieldDelegateListener:

open class ViewController: UIViewController, MaskedTextFieldDelegateListener {    
    @IBOutlet weak var listener: MaskedTextFieldDelegate!
    @IBOutlet weak var field: UITextField!
    
    open func textField(
        _ textField: UITextField,
        didFillMandatoryCharacters complete: Bool,
        didExtractValue value: String
    ) {
        print(value)
    }
}

All set. Run.

Sample project is located under the Source/Sample.