通常你会使用
fatalErr或()
或
preconditionFailure()
f或 that.
These do exactly the same: terminating the program, theref或e the code after this stamement never gets executed. All of the functions that have this behaviour are annotated with the @n或eturn
attribute
你也可以这样做:
func getInt() -> Int {
fatalErr或()
}
函数应该返回一个Int,但是因为程序永远不会到达那个点,所以你不需要返回任何东西.