0

All,

I have numerous arrays in the top of my .m file :

@interface ViewController ()
@property NSArray *allLogos;
@property NSArray *allcontent;
@property NSArray *allpostode;
@property NSArray *allname;
@property NSArray *alladdress;
@property NSArray *alladdress2;
@property NSArray *alllat;
@property NSArray *alllong;
@property NSArray *alllocationsID;
@property NSArray *alllocationsCity;

I need these as global arrays, so all the methods can see these. I have completely forgot how to make sure these NSArrays can be seen in all methods in the .m file. I need to do this because methods update these Arrays and then tableViews and PickerViews need to use them for .count etc. thanks

  • why not wrap them in a class? If you want only a single copy then use a Singleton. – Anoop Vaidya Mar 10 '14 at 09:26
  • i can wrap then in a class like class.h file I get that. I hear the Singleton word a lot but not exactly sure what it means – user3328028 Mar 10 '14 at 09:27
  • 1
    Singleton Class is a way of design. You have only one class and its instance. Each of your object have access to one instance which is shared. Try searching you will find many examples of singleton class in obj-c – Anoop Vaidya Mar 10 '14 at 09:29
  • Here have a look at my post, I explained it: http://stackoverflow.com/questions/21906005/dynamic-global-variables-in-ios-app/21907111#21907111 – AntonijoDev Mar 10 '14 at 09:33
  • as @AntonijoDev said, Singleton class is a best way to accomplish this – Himanshu Joshi Mar 10 '14 at 09:37
  • thanks guys, I am looking at the singleton class now, but still unsure I don't really need to run it with GCD. – user3328028 Mar 10 '14 at 09:38
  • @user3328028 Why does your title indicate `Objective-c++` when this is just `objective-c`? – Popeye Mar 10 '14 at 10:07

2 Answers2

0

Here you find how to create Singleton Class in Objective-C : [Objective-c singleton]:(What should my Objective-C singleton look like?)

Community
  • 1
  • 1
Irfan
  • 4,301
  • 6
  • 29
  • 46
  • Check this link too: http://stackoverflow.com/questions/5381085/how-to-create-singleton-class-in-objective-c – Irfan Mar 10 '14 at 09:52
0

If you want access following arrays in all class then don't make property in .m class.declaration in .m if you want to make private.

@interface ViewController : UIViewController
@property NSArray *allLogos;
@property NSArray *allcontent;
@property NSArray *allpostode;
@property NSArray *allname;
@property NSArray *alladdress;
@property NSArray *alladdress2;
@property NSArray *alllat;
@property NSArray *alllong;
@property NSArray *alllocationsID;
@property NSArray *alllocationsCity;
Gajendra Rawat
  • 3,673
  • 2
  • 19
  • 36
  • So if you want to make these global then don't put them as @property ? Is that what your saying ? – user3328028 Mar 10 '14 at 10:05
  • no no i am saying that if you have to access any variable in any other class then make its property, but set it into .h file instead of setting in .m class,if you set those in .m then they become private and other class can not access them. @user3328028 – Gajendra Rawat Mar 10 '14 at 10:20