What is this double underscore in Cocoa

前端 未结 4 1069
花落未央
花落未央 2020-12-05 22:10

The single underscore in Objective-C is apparently reserved for Apple\'s \"internal\" use (and was available for use with private instance variables prior to Apple\'s claim)

4条回答
  •  醉酒成梦
    2020-12-05 22:16

    It's not uncommon for compiler / library vendors to denote certain pre/postfixes as "reserved" for them. This is largely to avoid any inadvertent conflicts between types/defines/inherited variables.

    The post you refer to is regarding defines, not variables. Many compilers use double-underscores for the defines they provide and rely upon.

    As to why it the example code uses this style - the original author used the same coding style he likely employs in his day to day work and the potential conflict was never highlighted.

    You should be fine retaining the code sample as-is, but if it makes you uncomfortable then you can rename the variable.

提交回复
热议问题