mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-04-27 15:43:58 +00:00
Add a short note about final
keyword
It's a general good practice to mark classes as `final` unless they are designed to be subclassed.
This commit is contained in:
parent
33cd1f57ef
commit
8a54e8b738
@ -822,6 +822,17 @@ for _ in 0..<10 {
|
|||||||
See more here: https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html
|
See more here: https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// MARK: Preventing Overrides
|
||||||
|
|
||||||
|
// You can add keyword `final` before a class or instance method, or a property to prevent it from being overridden
|
||||||
|
class Shape {
|
||||||
|
final var finalInteger = 10
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prevent a class from being subclassed
|
||||||
|
final class ViewManager {
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Conditional Compilation, Compile-Time Diagnostics, & Availability Conditions
|
// MARK: Conditional Compilation, Compile-Time Diagnostics, & Availability Conditions
|
||||||
|
|
||||||
// Conditional Compilation
|
// Conditional Compilation
|
||||||
|
Loading…
Reference in New Issue
Block a user