Search code examples
iosobjective-cnsarrayviewcontrollerappdelegate

Calling App delegate array in ViewController


I am loading some of the arrays while I start up the application in AppDelegate. Can anyone tell me how I can call the arrays in ViewController for them to be used? The code in AppDelegate is as follows:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    Myclass *myclass = [[Myclass alloc] init];

    NSArray *W1 = [NSArray arrayWithObjects:[NSArray arrayWithObjects:[NSArray arrayWithObjects:[NSArray array], nil], nil], nil];
    //    NSArray *stringW1 = [myclass arrayFromContentsOfFileWithName:@"W1_custom2Float"];
    W1 = [myclass textToArray4dimFloat:@"W1_custom3_MOCVN_v3_wsqrt" dimension1:32 dimension2:1 dimension3:5 dimension4:5];
    //        W1 = [myclass textToArray4dimFloat:@"W1" dimension1:32 dimension2:1 dimension3:5 dimension4:5];

    //    NSLog(@"W1 is read");

    NSArray *W2 = [NSArray arrayWithObjects:[NSArray arrayWithObjects:[NSArray arrayWithObjects:[NSArray array], nil], nil], nil];
    //    NSArray *stringW2 = [myclass arrayFromContentsOfFileWithName:@"W2_custom2Float"];
    W2 = [myclass textToArray4dimFloat:@"W2_custom3_MOCVN_v3_wsqrt" dimension1:64 dimension2:32 dimension3:5 dimension4:5];
    //        W2 = [myclass textToArray4dimFloat:@"W2" dimension1:64 dimension2:32 dimension3:5 dimension4:5];

    //    NSLog(@"W2 is read");

    NSArray *Wf1 = [NSArray arrayWithObjects:[NSArray array], nil];
    //    NSArray *stringWf1 = [myclass arrayFromContentsOfFileWithName:@"Wf1_custom2Float"];
    Wf1 = [myclass textToArray2dimFloat:@"Wf1_custom3_MOCVN_v3_wsqrt" dimension1:3136 dimension2:1024];
    //        Wf1 = [myclass textToArray2dimFloat:@"Wf1" dimension1:3136 dimension2:1024];

    //    NSLog(@"Wf1 is read");

    NSArray *Wf2 = [NSArray arrayWithObjects:[NSArray array], nil];
    //    NSArray *stringWf2 = [myclass arrayFromContentsOfFileWithName:@"Wf2_custom2Float"];
    Wf2 = [myclass textToArray2dimFloat:@"Wf2_custom3_MOCVN_v3_wsqrt" dimension1:1024 dimension2:17];
    //        Wf2 = [myclass textToArray2dimFloat:@"Wf2" dimension1:1024 dimension2:14];

    //    NSLog(@"Wf2 is read");
    //
    NSArray *B1 = [NSArray array];
    //    NSArray *stringB1 = [myclass arrayFromContentsOfFileWithName:@"B1_custom2Float"];
    B1 = [myclass textToArray1dimFloat:@"B1_custom3_MOCVN_v3_wsqrt" dimensions:32];
    //    B1 = [myclass textToArray1dimFloat:@"B1" dimensions:32];

    //    NSLog(@"B1 is read");

    NSArray *B2 = [NSArray array];
    //    NSArray *stringB2 = [myclass arrayFromContentsOfFileWithName:@"B2_custom2Float"];
    B2 = [myclass textToArray1dimFloat:@"B2_custom3_MOCVN_v3_wsqrt" dimensions:64];
    //    B2 = [myclass textToArray1dimFloat:@"B2" dimensions:64];

    //    NSLog(@"B2 is read");

    NSArray *Bf1 = [NSArray array];
    //    NSArray *stringBf1 = [myclass arrayFromContentsOfFileWithName:@"Bf1_custom2Float"];
    Bf1 = [myclass textToArray1dimFloat:@"Bf1_custom3_MOCVN_v3_wsqrt" dimensions:1024];
    //    Bf1 = [myclass textToArray1dimFloat:@"Bf1" dimensions:1024];

    //    NSLog(@"Bf1 is read");

    NSArray *Bf2 = [NSArray array];
    //    NSArray *stringBf2 = [myclass arrayFromContentsOfFileWithName:@"Bf2_custom2Float"];
    Bf2 = [myclass textToArray1dimFloat:@"Bf2_custom3_MOCVN_v3_wsqrt" dimensions:17];
    //    Bf2 = [myclass textToArray1dimFloat:@"Bf2" dimensions:14];

    return YES;
}

W1, W2, Wf1, Wf2, B1, B2, Bf1, Bf2 are the arrays.


Solution

  • You need to add those objects into .hfile

    @property (strong, nonatomic)NSArray *W1;
    

    then assign values into didFinishLaunchingWithOptions.Sample below

    self.W1 = [myclass textToArray4dimFloat:@"W1_custom3_MOCVN_v3_wsqrt" dimension1:32 dimension2:1 dimension3:5 dimension4:5];
    

    Now you can access all those property into application any where.

        #include "MyAppDelegate.h"
       NSArray *arObj = ((MyAppDelegate *)[UIApplication sharedApplication].delegate). W1;