how and where do I initialize an global NSMutableArray in Xcode 5(如何以及在哪里初始化 Xcode 5 中的全局 NSMutableArray)
问题描述
我正在尝试初始化一个全局 NSMutableArray,我可以在以后添加整数.我只需要知道我应该如何以及在哪里初始化我的数组,以便我以后在程序中使用的任何函数都可以访问和更改它.另外我正在使用 Xcode 5,并且知道数组的长度需要为 180.
I am trying to initialize a global NSMutableArray that I can add integers to later. I just need to know how and where I should initialize my array so that it can be accessed and changed by any function that I use later in my program. Also I am using Xcode 5 and know that the array needs to be 180 in length.
推荐答案
您可以创建一个单例类并在该类上为您的数组定义一个属性.
You could create a singleton class and define a property for your array on that class.
例如:
// .h file
@interface SingletonClass : NSObject
@property (nonatomic,retain) NSMutableArray *yourArray;
+(SingletonClass*) sharedInstance;
@end
// .m file
@implementation SingletonClass
+(SingletonClass*) sharedInstance{
static SingletonClass* _shared = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_shared = [[self alloc] init];
_shared.yourArray = [[NSMutableArray alloc] init];
});
return _shared;
}
@end
这篇关于如何以及在哪里初始化 Xcode 5 中的全局 NSMutableArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何以及在哪里初始化 Xcode 5 中的全局 NSMutableArray
基础教程推荐
- Android文本颜色不会改变颜色 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
