IPHONE APP中的全局变量 [英] Global variables in IPHONE APP
本文介绍了IPHONE APP中的全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Objective C和其他文件中使用extern声明和使用全局变量.
How to declare and use global variable with extern in Objective C and other files.
我想在1.h文件和1.m文件中定义和分配全局变量,并想在2.m文件中使用它
I want to define and assign the global variable in 1.h file and 1.m and want to use that in 2.m file
我正在定义
1.h
extern const NSString *str;
1.m
NSString *str=@"HELLO";
在 2.m
中,我正在导入 1.h
想访问str但给我2.o错误.
want to access str but giving me 2.o error.
推荐答案
如果这些是应用程序设置,则应考虑使用NSUserDefaults.如果是常量,则应在前缀头文件中定义它们.
If these are application settings you should consider using NSUserDefaults. If it's constants, you should define them in prefix header file.
这篇关于IPHONE APP中的全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文