user3372120
user3372120

Reputation: 144

NSUrl always need NSUrlRequest to run?

I have this code:

NSURL *url = [NSURL URLWithString:@"http://www.google.com"];

NSURLRequest *request = [NSURLRequest requestWithURL:url];

[webView loadRequest:request];

My question is, its possible loadRequest without declare a variable 'request' (NSURLRequest)? if not why we always need to do this?

Upvotes: 1

Views: 51

Answers (1)

Wain
Wain

Reputation: 119021

You need a URL request. Not clear if you don't want one or you don't want a variable for it.

The request allows you to set things like timeout and cache options for how the request should be loaded.

For the variable, technically you only need one line:

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];

but it isn't as easy to work with / debug when there are issues. So, you don't need to define local variables, but it usually helps you to understand and maintain your code.

Upvotes: 1

Related Questions