Redeclaring members in an extension hides the original member *sometimes*. Why?

前端 未结 1 465
栀梦
栀梦 2021-01-05 21:11

By chance, I discovered that you can do this without the compiler complaining:

extension Date {
    var timeIntervalSinceNow: TimeInterval {
        return 1         


        
相关标签:
1条回答
  • 2021-01-05 21:41

    This works because you are declaring this extension in a separate module from the original variable declaration.

    Across modules a variable name can be overloaded but in my mind this has been a shortcoming of Swift as there is currently no way to explicitly state which module declaration it is that you want.

    0 讨论(0)
提交回复
热议问题