Proper Objective-C Helper “Wannabe” Private methods?

前端 未结 3 475
南旧
南旧 2021-02-06 18:01

While I hate to beat a horse to death on this subject (I\'ve read through various articles about this), but would just like to get more opinions on this matter before I create m

3条回答
  •  名媛妹妹
    2021-02-06 18:22

    I would use a class extension, definitely. In the implementation file, include something like this above your @implementation:

    @interface A ()
    - (void) doErrorChecking;
    @end
    

    Then use the method in code as needed. Although due to objective-c's dynamic nature no method is truly private, this will obscure the method from your interface file while still technically including it in your own 'private' interface. In general, keep your .h file for methods and properties that are ok for public use, while limiting private use methods and properties to a class extension in the implementation file.

提交回复
热议问题