Objective-C 程序中的全局变量 [英] Global variable in Objective-C program

查看:29
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆