Generic way to handle UITextField Responders in Xcode Swift Project

Sandeep Kumar
1 min readOct 17, 2017

I think you all are familiar with UITextField Delegates and writing code for different textfields responding buttons inside each view controller repeatedly.

So your problem can be resolved by my generic code slice if your case matches with mine. if you want next button in keyboard to respond to next textfield and if textfield is last then show done button and resign keyboard on tap of done button, you don’t have to write textfield delegates in each view controller. Just take a look at generic TFResponder class and reduce your number of lines in code.

You can use above class to solve your problem by just writing one line of code inside viewDidLoad of view controller and enjoy.

TFResponder.shared.addResponders(textFields)

where parameter passed textFields is IBOutlet collection of textField outlets.

Remember outlets array should be in right order in which you want to respond TextFields.

Catch sample project on Github: https://github.com/SandeepSpider811/TFResponder

--

--