diff options
author | mofarajmandi <mfarajmandi@gmail.com> | 2020-10-17 16:19:26 -0300 |
---|---|---|
committer | Mo Farajmandi <mo.farajmandi@redspace.com> | 2020-10-17 21:13:50 -0300 |
commit | 8a54e8b738ab32f5e968e39929a0bd86e0d78aa2 (patch) | |
tree | 0bcc43fe530a936ac4eb05a36ef9a3318d019b05 | |
parent | 33cd1f57ef49f4ed0817e906b7579fcf33c253a1 (diff) |
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.
-rw-r--r-- | swift.html.markdown | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/swift.html.markdown b/swift.html.markdown index 689c5191..3981a4ce 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -822,6 +822,17 @@ for _ in 0..<10 { 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 // Conditional Compilation |