0

I want to declare a global array so I can use this in all methods and every where in my app. I have two buttons which 1 shows the next image in the array and the other button shows the previous image shown. I want both buttons to use the same array.

NSMutableArray *images = [[NSMutableArray alloc] 
                          initWithObjects:@"Americans.png",
                                          @"Approach.png",
                                          @"Arianny.png",
                                          @"Atoms.png",
                                          @"Australia.png",nil];
Peter DeWeese
  • 18,141
  • 8
  • 79
  • 101

2 Answers2

1

You might want to take a look at this question. I'd suggest going with putting it in your AppDelegate or creating a singleton.

Community
  • 1
  • 1
john
  • 3,043
  • 5
  • 27
  • 48
0

You can use dispatch_once to allocate a static object:

static dispatch_once_t once;
static NSMutableArray * images;
dispatch_once(&once, ^ { images = /*blah*/; });

Generally you would wrap this in a function or a class method of a utility class.

Mark F
  • 457
  • 2
  • 6