gpt4 book ai didi

ios - 防止子类覆盖 Swift 中的继承函数

转载 作者:搜寻专家 更新时间:2023-10-30 22:22:38 27 4
gpt4 key购买 nike

有没有办法防止子类覆盖 Swift 中继承的函数?

最佳答案

看看 final 关键字。

根据文档,

You can prevent a method, property, or subscript from being overridden by marking it as final. Do this by writing the final modifier before the method, property, or subscript’s introducer keyword (such as final var, final func, final class func, and final subscript).

Any attempt to override a final method, property, or subscript in a subclass is reported as a compile-time error. Methods, properties, or subscripts that you add to a class in an extension can also be marked as final within the extension’s definition.

您可以在 Inheritance section 底部找到更多信息Swift 语言指南(查找“防止覆盖”小节)。

关于ios - 防止子类覆盖 Swift 中的继承函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31422913/

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