What is the Never return type?

前端 未结 4 1453
我在风中等你
我在风中等你 2021-01-01 10:36

What does a func with return type Never do?

For example:

func addNums() -> Nev         


        
4条回答
  •  悲&欢浪女
    2021-01-01 10:55

    Never indicates that the function will never return. It's intended to be used for things like fatalError which cause your program to crash intentionally, often after logging an error. You probably shouldn't use it unless you're doing something like making a handler for catastrophic errors in your application.

    This is different from a function which just doesn't return a value, as in your second snippet. You could also write that as func addNums() -> Void.

提交回复
热议问题