black friday sale

Flat 10% off on the purchase of any two apps or more. Use coupon code - FESTIVAL10

Grab It Now
Check Mobile App
Read now
Start a Project

Never Keyword in Swift

Save

The Never keyword is a special return type in Swift. When this function call occurs, it tells the compiler that exec will never return

According to Apple:-

“The return type of functions that do not return normally, that is, a type with no values.”

Never keyword used by fatalError() and preconditionFailure() functions.

We can use it as a return type when declaring a method, closure, or function that unconditionally throws an error, traps, or otherwise does not terminate.

func method1() -> Never {

    fatalError("Something very, very bad happened")

}

The first note (with regard to secondary error treatment) is perhaps particularly important. A function can never have complex arguments and throws – not necessarily crashes.

Let’s look at some interesting use cases and compare between never and void

Comparision between NEVER and VOID return type :

VOID:

That’s all for this article.

We hope you liked the article.

Please visit my other blogs here.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

css.php

The support is fast and do everything in their power to make it perfect. If you need customization it's also done right away. I had massive research to select Mobikul and now I'm sure it was the right one.

Igor Souza

Igor Souza

Talk to Sales

Global

Live Chat
Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home