I’m writing a class which retrieves and parses a file downloaded from a server.
I have a method inside the class which parses the information, and the information is downloaded when the class is initialized.
The problem is, sometimes, the method that parses the information is called before the information itself is downloaded.
FileParser *instance = [[FileParser alloc] initWithURL:@"somewhere"];
[instance parseData];
Every time the parseData method is called directly after the class is initialized, it fails because not all of the content is available.
How can I wait until all the information is downloaded before I continue executing the parseData method, without interrupting the main thread?
Any help appreciated.
you should think about using delegates.
You pass your dowloading class a delegate that will handle the downloaded data.
See here