How to prevent usage of other init methods other than my custom method in Objective-C

后端 未结 2 1765
小蘑菇
小蘑菇 2021-01-16 12:25

Background - in my iPhone app I have a custom UITableViewController - I was going to pass some required config to it by extending the existing \"(id)initWithStyle:(UITableVi

2条回答
  •  失恋的感觉
    2021-01-16 12:52

    I usually document this and put a [self doesNotRecognizeSelector:_cmd] call into the init methods that are not intended to be used.

    In conjunction, marking the method deprecated (see How do I flag a function as being deprecated in an iPhone Objective C header file?) prevents runtime suprises and gets you a warning at compile time.

提交回复
热议问题