gpt4 book ai didi

ios - 在为 iOS 开发时,如果我们不想子类化 View Controller 类,可以将它们标记为 Final 吗?

转载 作者:行者123 更新时间:2023-11-30 11:39:29 25 4
gpt4 key购买 nike

如果我们不想子类化 View Controller 类,那么标记 View Controller 类是否是提高性能的最后一件好事?

最佳答案

如果您正在编写逻辑上无法覆盖或不想被其他开发人员子类化的类或函数,最好将其标记为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.

You can mark an entire class as final by writing the final modifier before the class keyword in its class definition (final class). Any attempt to subclass a final class is reported as a compile-time error.

关于ios - 在为 iOS 开发时,如果我们不想子类化 View Controller 类,可以将它们标记为 Final 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49405792/

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