Hide Keyboard in app

Hi All,

I have just started to learn swiftui and just messing around.

I have created a form got a couple of text boxes in it with decimal keyboard and also a picker in the form

The problem I have is that when you click in the text box you can’t make the keypad go, is there a way to put a done button on the keypad?

@Seesor Welcome to the community!

What I typically do is something like this, although there are other solutions.

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

    func hideKeyboard() {

You can also do this when the user taps return on the keyboard:

//Add the delegate to the class

//In viewDidLoad add the following
//Delegate need to connect return key on keyboard
        addField.delegate = self

func textFieldShouldReturn(_ taskFiled: UITextField) -> Bool {
        if yourTextField!.isEmpty {
            //Empty so close
            taskFiled.text = ""
            return true
        //Do whatever the field does here.
        return true


Thanks Mark I will give this a try