The final keyword exists in most programming languages, indicating that it is not allowed to inherit or reoperate the modified content. In Swift, the final keyword can be modified before class, func and var.
Usually everyone believes that using final can better version control of the code, perform better performance, and make the code safer. The following is an example code to introduce to you the use of final keyword to prevent rewriting of swift.
/** Use final keyword to prevent rewrite Final, final, final; decisive; unchangeable If the final modify class means that this class cannot be inherited. If the attribute or method is modified, it means that the corresponding attribute or method cannot be rewritten. */ class Observer { // final plus var storeProperty: Int = 0 { willSet { print("storeProperty father will Set") } didSet { print("storeProperty father did Set") } } // final // Cannot set attribute observer for calculation attributes var computeProperty: Int { get { return 0 } set { print("Do nothing!") } } //final func dodododTest() -> Void { print("dadadadadaddadaad") } } class ChildOfObserver: Observer { // You can override the variable storage attributes in the parent class override var storeProperty: Int { willSet { print("storeProperty will Set") } didSet { print("storeProperty did Set") } } // You can rewrite the attribute observer for computed attributes in the parent class override var computeProperty: Int { willSet { print("computeProperty will Set") } didSet { print("computeProperty did Set") } } override func dodododTest() { } } let co = () = 10
The above is what the editor introduced to you using the final keyword to prevent rewriting of Swift. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!