<aside> 💡 최종_발표_수정_마지막_진짜_마지막_찐막.pdf
</aside>
Preventing Overrides
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 asfinal var
,final func
,final class func
, andfinal 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 theclass
keyword in its class definition (final class
). Any attempt to subclass a final class is reported as a compile-time error.
해당 키워드를 사용하면 클래스, 프로퍼티의 상속, 오버라이딩을 막는다
final 키워드가 붙어 있으면 해당 클래스는 더 이상 오버라이딩 여부를 확인할 필요가 없기 때문에 컴파일 단계에서 해당 function을 고정시킬수 있다. (static dispatch)
Swift - Inheritance | https://docs.swift.org/swift-book/LanguageGuide/Inheritance.html
Increasing Performance by Reducing Dynamic Dispatch | https://developer.apple.com/swift/blog/?id=27
final Keyword | https://ichi.pro/ko/final-kiwodeu-swift-5-ios-82713309708267