gpt4 book ai didi

ios - 生产应用程序中的 Swift 断言行为

转载 作者:IT王子 更新时间:2023-10-29 05:22:54 24 4
gpt4 key购买 nike

我正在阅读 Swift e-book 中的断言部分看起来断言的工作方式与 Objective-C 中的断言非常相似。但是,在文档中的任何地方我都找不到有关作为生产应用程序运行时运行时行为的任何信息。 Objective-C 的 NSAssert promise 永远不会因断言失败而终止生产应用程序。在 Swift 中也是这样吗?

最佳答案

基于 Apple 在 their documentation 中使用的语言,我会说断言在生产环境中会被忽略。

If your code triggers an assertion while running in a debug environment, such as when you build and run an app in Xcode, you can see exactly where the invalid state occurred and query the state of your app at the time that the assertion was triggered. An assertion also lets you provide a suitable debug message as to the nature of the assert.

在“注释” block 中:

Assertions cause your app to terminate and are not a substitute for designing your code in such a way that invalid conditions are unlikely to arise. Nonetheless, in situations where invalid conditions are possible, an assertion is an effective way to ensure that such conditions are highlighted and noticed during development, before your app is published.

关于ios - 生产应用程序中的 Swift 断言行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24037935/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com