Use Class Extension for Selective Visibility in Objective-C

后端 未结 2 2019
谎友^
谎友^ 2021-01-02 07:48

Would it make any sense to put class extensions in their own .h files and #import them selectively to get various levels of visibility for a class\

2条回答
  •  清酒与你
    2021-01-02 08:25

    Class extension (as opposed to subclassing) in Objective-C is accomplished with Categories. In Xcode, go to File > New > File and select Objective-C Category. It will ask you what to call the category and what class it should extend. You'll get a .h/.m pair in which to put your interface and implementation, respectively. If you want access to the features provided in your extension, just import its .h file.

提交回复
热议问题