How to load database at App Start up?

180 views Asked by At

I'm developing an App that Loads database of Airports. I put the database ".JSON" File in my Application in Xcode. Everything's working well, except a Very long time to load the database.

I used this way to get an array from the JSON File.

-(void)readDataFromFile
{
    NSString * filePath =[[NSBundle mainBundle] pathForResource:@"airports" ofType:@"json"];

    NSError * error;
    NSString* fileContents =[NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error];


    if(error)
    {
        NSLog(@"Error reading file: %@",error.localizedDescription);
    }


    self.airports = (NSArray *)[NSJSONSerialization JSONObjectWithData:[fileContents dataUsingEncoding:NSUTF8StringEncoding] options:0 error:NULL];



    NSLog(@"%@",self.airports);



}

MY QUESTION

How can I move this time of wait when the application load? In Small Words I need to load the database at the Start up !

1

There are 1 answers

8
Robert J. Clegg On

The earliest time to do this is in the application didFinishLaunchingWithOptions method in your app delegate class.