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

后端 未结 4 1919
渐次进展
渐次进展 2020-12-19 10:32

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

4条回答
  •  清歌不尽
    2020-12-19 11:11

    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
    

提交回复
热议问题