toast toast - 5 months ago 27
iOS Question

Is it okay to segue, without calling a completion handler, if not needed?

Say I have a function that has a completion handler, then calls another function, with a completion handler like this:

func register(withCompletion complete: @escaping (() -> Void)) {
self.sendRegisterRequest(withCompletion: { (error: Error?) -> () in

if error != nil {
self.performSegue(withIdentifier: "ErrorVCSegue", sender: nil)
else {

In the event of an error, it will segue away with calling

Am I ok to segue away like this, without calling
? I do not need to return from this function as I'm now wanting to go to another View Controller.



This is a bad idea. A completion handler should be called no matter what. The caller is waiting for a response. It wants to know when it is done. That's the whole point of having a completion handler.

In your case (like many other cases), it would be much better if the completion handler accepted a boolean parameter (and/or an error parameter). This way the completion handler provides some basic information about the success or failure of the method.