[Solved] How do I implement UITextFieldDelegate [closed]

Your ViewController should be an UITextFieldDelegate. You then set the current ViewController as the delegate of the textField, in this case in viewDidLoad().

Implement textFieldShouldReturn so the textField delegates the return task (textFieldShouldReturn) to the ViewController. In this method call resignFirstResponder, this way the keyboard will disappear. Example:

import UIKit

class ViewController: UIViewController, UITextFieldDelegate {

    @IBOutlet weak var someTextField: UITextField!

    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        return true

    override func viewDidLoad() {

        someTextField.delegate = self



solved How do I implement UITextFieldDelegate [closed]