Class variable defined at @implementation rather than @interface?

后端 未结 6 2066
夕颜
夕颜 2020-11-29 02:46

I\'m new to Objective-C, but I am curious about something that I haven\'t really seen addressed anywhere else.

Could anyone tell me what is the difference between a

6条回答
  •  执念已碎
    2020-11-29 03:25

    The latter is not defining an instance variable. Rather, it is defining a global variable in the .m file. Such a variable is not unique to or part of any object instance.

    Such globals have their uses (roughly equivalent C++ static members; e.g. storing a singleton instance), but normally you would define them at the top of the file before the @implementation directive.

提交回复
热议问题