Best way of preventing other programmers from calling -init

后端 未结 5 1971
醉梦人生
醉梦人生 2020-12-23 11:43

When designing a class hierarchy, sometimes the subclass has added a new initWithSomeNewParam method, and it would be desirable to disable calls to the old

5条回答
  •  旧时难觅i
    2020-12-23 12:21

    To add to what @DarkDust posted, you could alternatively use UNAVAILABLE_ATTRIBUTE

    - (id)init UNAVAILABLE_ATTRIBUTE;
    

    This will throw an error when a user tries to call init on an instance of this class.

提交回复
热议问题