Overriding methods in Swift extensions

前端 未结 5 1478
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 16:13

I tend to only put the necessities (stored properties, initializers) into my class definitions and move everything else into their own extension, kind of like a

5条回答
  •  太阳男子
    2020-11-22 16:48

    Extensions cannot/should not override.

    It is not possible to override functionality (like properties or methods) in extensions as documented in Apple's Swift Guide.

    Extensions can add new functionality to a type, but they cannot override existing functionality.

    Swift Developer Guide

    The compiler is allowing you to override in the extension for compatibility with Objective-C. But it's actually violating the language directive.

提交回复
热议问题