How to use async and await on a default function?

193 views Asked by At

I am having a problem when I am trying to add async and await to a default function.

The function I am trying to add it to is:

func inputBar(_ inputBar: InputBarAccessoryView, didPressSendButtonWith text: String)

But it looks like when I add async the function will no longer get called when I press the button because it apparently is a different function. How can I fix this?

1

There are 1 answers

1
lorem ipsum On BEST ANSWER

You can't change Apple's function but you can incorporate.

var task: Task<Void, Never>? = nil // Put this at class level.

func inputBar(_ inputBar: InputBarAccessoryView, didPressSendButtonWith text: String){

    task?.cancel() // Cancels previous operations
    task = Task{
         //Do something here
    }
}