-
assert:传统的C样式断言。
assert主要作用是在测试期间进行内部健全性检查,在release状态下是不运行。
func assert(_ condition: @autoclosure () -> Bool, _ message: @autoclosure () -> String = String(), file: StaticString = #file, line: UInt = #line)
参数:
condition:要测试的条件。condition仅在playgrounds和debug中进行评估。如果condition求值为false,则在打印后停止以可调试状态执行程序message。
message:一个字符串打印如果condition被评估false。默认值为空字符串。
file:message如果断言失败,则打印文件名。默认值是调用的文件。assert(_:_:file:line:)
line:要打印的行号以及message断言是否失败。默认值是调用的行号。assert(_:_:file:line:)
-
assertionFailure:表示内部完整性检查失败。
assertionFailure使用此功能能让App停止运行,说白了可以制造崩溃。同样在debug执行,在release下不执行。
func assertionFailure(_ message: @autoclosure () -> String = String(),file: StaticString = #file, line: UInt = #line)
参数:
message:在playgrounds和debug中打印的字符串。默认值为空字符串。
file:要打印的文件名message。默认值是调用的文件。assertionFailure(_:file:line:)
line:要打印的行号message。默认值是调用的行号。assertionFailure(_:file:line:)
-
precondition:必须要满足条件,才会执行后面的。
precondition与assert类似,只是precondition不管是在debug还是release都会执行,在debug下会打印输出。
func precondition(_ condition: @autoclosure () -> Bool, _ message: @autoclosure () -> String = String(), file: StaticString = #file, line:UInt = #line)
参数
condition:要测试的条件。
message:condition要false在playgrounds和debug中进行评估的字符串。默认值为空字符串。
file:message如果前提条件失败,则打印的文件名。默认值是调用的文件。
line:要打印的行号以及message断言是否失败。默认值是调用的行号。
-
preconditionFailure:表示违反了前提条件,直接终止App。
preconditionFailure与assertionFailure类似,只是precondition不管是在debug还是release都会执行,在debug下会打印输出。
func preconditionFailure(_ message: @autoclosure () -> String = String(),file: StaticString = #file, line: UInt = #line) -> Never
参数
message:在操场或-Onone构建中打印的字符串。默认值为空字符串。
file:要打印的文件名message。默认值是调用的文件。
line:要打印的行号message。默认值是调用的行号。
-
fatalError:无条件地打印给定的消息并停止执行。
func fatalError(_ message: @autoclosure () -> String = String(), file:StaticString = #file, line: UInt = #line) -> Never
参数
message:要打印的字符串。默认值为空字符串。
file:要打印的文件名message。默认值是调用的文件。
line:要打印的行号message。默认值是调用的行号。
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。