Swift override function in extension

后端 未结 2 932
慢半拍i
慢半拍i 2020-12-02 02:17

If I have a class:

class Spaceship {
    function prepareForLiftoff() throws {
        //Start the countdown!
    }
}

I ori

2条回答
  •  春和景丽
    2020-12-02 02:31

    From the documentation:

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

    The documentation lists carefully and precisely what an extension is allowed to do.

    As to your question:

    Is there anyway to override a function of a particular class

    Yes, it's called subclassing.

提交回复
热议问题