how to block a superclass method to be called to a subclass

后端 未结 5 1703
情歌与酒
情歌与酒 2021-01-19 03:37

I\'m extending the functionality of a class with a subclass, and I\'m doing some dirty stuff that make superclass methods dangerous (app will hang in a loop) in the context

5条回答
  •  伪装坚强ぢ
    2021-01-19 03:44

    You can override whichever methods you want to block in your subclass's .h file. You can make dangerousMethod unavailable by placing the following in your .h file.

    - (int)dangerousMethod __attribute__((unavailable("message")));
    

    This will make the dangerousMethod method unavailable to anyone using your subclass.

    To keep other code from using the superclass's version this method, you can further restrict by putting this in your .m file.

    - (int)dangerousMethod 
    {
        return nil;     
    }
    

提交回复
热议问题