Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
542 views
in Technique[技术] by (71.8m points)

ios - how and where do I initialize an global NSMutableArray in Xcode 5

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In your AppDelegate.h file -

@property(nonatomic,retain) NSMutableArray *sharedArray;

In AppDelegate.m

@synthesize sharedArray;

In didFinishLaunchingWithOptions -

sharedArray = [[NSMutableArray alloc]init];

Now,

make create shared object of AppDelegate like-

mainDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];

and access sharedArray where you want to access using-

mainDelegate.sharedArray

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...