Private and protected methods in Objective-C

前端 未结 2 1263
栀梦
栀梦 2020-12-09 07:34

What is the recommended way to define private and protected methods in Objective-C? One website suggested using categories in the implementation file for private methods, an

2条回答
  •  时光取名叫无心
    2020-12-09 08:11

    There are no "real" private methods in Objective C, as the run-time will allow, via documented public APIs, access any method in any class by using their string names.

    I never do separate interface files for "private" methods, and let the compiler complain if I try to use these any of these methods outside of file scope.

    The XX_ seems to be the ad hoc means to create a pseudo namespace. The idea is to read Apple's docs and the docs of any frameworks you might use at any time in the future, and pick an XX prefix that none of these others is ever likely to use.

提交回复
热议问题