-2

I am trying to load web data asynchronously. I understand that I can use the following, but I don't know how to call the void(load) method. How do I call this? It doesn't appear to be called automatically. Thanks!

- (void)load
{
NSURL *myURL = [NSURL URLWithString:[NSString 
stringWithFormat:@"http://www.website.com"]];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myURL 
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];

[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
Brandon
  • 2,163
  • 6
  • 40
  • 64

2 Answers2

1

Like H2CO3 said, you should call the method by using [self load]. I would expect you want to call it in the method -(void)viewDidLoad. This is called once for when the view is loaded.

Douglas
  • 2,524
  • 3
  • 29
  • 44
0
__attribute__((constructor)) 
- (void)load
{
NSURL *myURL = [NSURL URLWithString:[NSString 
stringWithFormat:@"http://www.website.com"]];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myURL 
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];

[[NSURLConnection alloc] initWithRequest:request delegate:self];
}  

It's run when a shared library is loaded, typically during program startup.

Take a look at How exactly does __attribute__((constructor)) work?

Community
  • 1
  • 1
Parag Bafna
  • 22,812
  • 8
  • 71
  • 144