Reputation: 235
what is the difference between NSURLConnection
and NSURL
?
i mean if i am downloading a file, does it make and difference which one i use?
Rgds
for:
NSString *myUrl = @"http://www.test.com/";
NSString *returnData = [NSString stringWithContentsOfURL:[NSURL URLWithString: myUrl]];
or
NSString *myUrl = @"http://www.test.com/";
NSURLRequest *myRequest = [[NSURLRequest alloc] initWithURL: [NSURL URLWithString:myUrl] ];
NSString *returnData = [NSURLConnection sendSynchronousRequest:myRequest returningResponse: nil error: nil ];
whats the difference?
thks
Upvotes: 0
Views: 2117
Reputation: 21144
Best thing about NSURLConnection is its asynchronous behaviour so that you dont have to wait until the url is loaded.
Upvotes: 1
Reputation: 188064
The Connection
An
NSURLConnection
object provides support to perform the loading of a URL request.
The Request
NSURLRequest
objects represent a URL load request in a manner independent of protocol and URL scheme.
E.g. requestWithURL
:
Creates and returns a URL request for a specified URL with default cache policy and timeout value.
+ (id)requestWithURL:(NSURL *)theURL
The URL
The
NSURL
class provides a way to manipulate URLs and the resources they reference.NSURL
objects understand URLs as specified in RFCs 1808, 1738, and 2732. ...To get the contents of a URL,
NSString
providesstringWithContentsOfURL:
andNSData
providesdataWithContentsOfURL:
.
References:
Upvotes: 1