如何制作全局数组? [英] How to make a Global Array?

查看:127
本文介绍了如何制作全局数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我阅读了这篇文章,这几乎是什么我在寻找。但是...它不起作用。我想我不打算去单身人士的对象,而是在Global.h文件中创建数组,或将其插入到_Prefix文件中。



两次我都这样做,我得到的错误:



在'static'之前的预期说明符 - 限定符列表

<并且它不起作用。所以...我不知道如何让它工作,我可以删除外部和它的作品,但我觉得我需要它,使其不断。



<最终目标是让这个可变数组可以从我的项目中的任何对象或任何文件访问。帮助将不胜感激!



这是我的Globals.h文件的代码:

  #import< Foundation / Foundation.h> 

static extern NSMutableArray * myGlobalArray;

我认为我在实现文件中不需要任何东西。如果我把它放在前缀文件中,错误是一样的。



编辑



因此,我从Globals中删除了.m文件,并且我只是在Globals.h中提供了代码。假设我将继续这种有全局变量的可怕做法(我知道这很糟糕,我只想测试一下),现在我有一个新的错误。它说:
$ b

声明说明符中有多个存储类



如果我删除extern如果我删除静态它的作品,但有两个不...现在什么?



****双编辑****



好的,所以我尝试将数组添加到我的UIApplication委托中,但是我做错了,因为它不起作用。有人可以给我一些示例代码,以便将它放置在哪里吗?我不知道它是否应该在实现中或其他地方进行,并且一旦数组初始化后如何从其他文件中访问它......我是否为数组设置了一个新的变量?或者是什么?

解决方案

这是我正在寻找的东西:

http://derekneely.com/tag/app-delegate/

感谢您指引我朝着正确的方向发展!


So, I read this post, and it's pretty much exactly what I was looking for. However... it doesn't work. I guess I'm not going to go with the singleton object, but rather making the array in either a Global.h file, or insert it into the _Prefix file.

Both times I do that though, I get the error:

Expected specifier-qualifier-list before 'static'

and it doesn't work. So... I'm not sure how to get it to work, I can remove extern and it works, but I feel like I need that to make it a constant.

The end goal is to have this Mutable Array be accessible from any object or any file in my project. Help would be appreciated!

This is the code for my Globals.h file:

#import <Foundation/Foundation.h>

static extern NSMutableArray * myGlobalArray;

I don't think I need anything in the implementation file. If I were to put that in the prefix file, the error was the same.

EDIT

So, I removed the .m file from Globals, and I just have the code about in Globals.h. Assuming I am going to continue with this terrible practice of having global variables (I know it's bad, I just want to test this out), I now have a new error. It says:

"Multiple storage classes in declaration specifiers"

If I remove "extern" it works and if I remove "static" it works, but having both doesn't... what now?

****Double Edit****

Aright, so I've tried adding the array to my UIApplication Delegate, but I'm doing it wrong because it isn't working. Could someone give me some example code as to where to place it an access it? I don't know if it should go in the implementation, or somewhere else, and once the array is initialized how to access it from the other files... Do I set a new variable to the array, or something?

解决方案

This is what I was looking for:

http://derekneely.com/tag/app-delegate/

Thank you for pointing me in the right direction!

这篇关于如何制作全局数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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