- The final keyword is used to indicate that a class, method, or property cannot be overridden or subclassed
- Declaring a class as final, it means that it’s the end of the inheritance chain for that class, and it cannot be subclassed further.
final class LastClass {
// Class definition
}
// error! PleaseNot class cannot inherit from a 'final' class 'LastClass'
class PleaseNot: LastClass {
}
Beneficial
- Preventing Subclassing
- final ensures that its functionality remains intact and cannot be altered by subclasses
- Performance Optimization
- The compiler can perform certain optimizations on final classes and methods because it knows they cannot be overridden
Dispatch
- Grand Central Dispatch(GCD)
- Execute code concurrently on multicore hardware by submitting work to dispatch queues managed by the system
참조
https://gurjit-singh.medium.com/what-is-final-class-in-swift-53a0246f6abd
'iOS > Swift' 카테고리의 다른 글
| UnsafePointer (0) | 2024.05.08 |
|---|---|
| NWPathMonitor (0) | 2024.05.08 |
| UnsafePointer (0) | 2024.04.29 |
| Singleton Pattern (0) | 2024.04.15 |
| CombineLatest Vs Zip (0) | 2024.04.08 |