Objective-C程序中的全局变量 [英] Global variable in Objective-C program
本文介绍了Objective-C程序中的全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将一个数字作为一个全局变量存储。我使用什么语法,我的应用程序的其他部分如何访问该变量?
I want store a number as a global variable. What syntax do I use, and how can other parts of my application access that variable?
推荐答案
当应用程序终止并重新启动时持久化)添加到您选择的头文件(*。h):
For a standard global variable (not persistent when the app is terminated and restarted) add this to a header file (*.h) of your choice:
extern NSInteger MYGlobalVariable;
然后把这个放在执行文件中; (* .m,* .c,* .cpp):
Then put this in the implementation file; (*.m, *.c, *.cpp):
MYGlobalVariable = 0; // Or any other default value.
这就是您如何做面包和黄油全局变量。
That is how you do a bread and butter global variable.
这篇关于Objective-C程序中的全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文