gpt4 book ai didi

swift - NS_CLOSED_ENUM 实际上是不可编辑的吗?

转载 作者:搜寻专家 更新时间:2023-11-01 06:52:23 24 4
gpt4 key购买 nike

According the Apple docs,为 Swift 5 添加的新 NS_CLOSED_ENUM 宏是不可更改的。这怎么可能?我不能只清理构建、添加值并重新编译我的应用程序吗?

Important

Once an enumeration is marked as closed, it's a binary- and source-incompatible change to add a new value. If you have any doubt about an enumeration gaining a private or additional public case in the future, use the NS_ENUM macro instead.

我能够为我们的应用程序添加一个新值并编译得很好(在更新 switch cases 之后)。

最佳答案

当您使用 NS_CLOSED_ENUM 时,您向 API 的使用者 promise 枚举永远不会改变,无论是现在还是将来。

当然,没有什么可以阻止您进行更改,但如果您这样做,您就违背了 promise 。如您所说,在更新 switch case 之后编译良好

如果您声明它是一个封闭的枚举,您就是在告诉所有开发人员他们永远不必担心它会发生变化。这在 Swift 5 中很有用,它添加了一个 @unknown default。 build 于 switch处理未封闭枚举的语句。

参见 this post for more information .

关于swift - NS_CLOSED_ENUM 实际上是不可编辑的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56278768/

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