initWithRequest :delegate:
Returns an initialized URL connection and begins to load the data for the URL request.
Parameters of [NSURLConnection initWithRequest]
- request
- The URL request to load. The request object is deep-copied as part of the initialization process. Changes made to request after this method returns do not affect the request that is used for the loading process.[NSURLConnection initWithRequest]
- delegate
- The delegate object for the connection. The delegate will receive delegate messages as the load progresses. Messages to the delegate will be sent on the thread that calls this method. By default, for the connection to work correctly, the calling thread’s run loop must be operating in the default run loop mode. See
scheduleInRunLoop:forMode:
to change the run loop and mode.
Return Value
The URL connection for the URL request. Returns
nil
if a connection can't be initialized.Discussion of [NSURLConnection initWithRequest]
This is equivalent to calling
initWithRequest :delegate:startImmediately:
and passingYES
for startImmediately
.Special Considerations
During the download the connection maintains a strong reference to the delegate. It releases that strong reference when the connection finishes loading, fails, or is canceled.
Example of [NSURLConnection initWithRequest]
NSURLConnection *theConnection = [[[NSURLConnection alloc] initWithRequest:theRequest delegate:self] autorelease];
Example of [NSURLConnection initWithRequest]
DownloadDelegate *dd = [DownloadDelegate alloc];
NSURLConnection *c2 = [[NSURLConnection alloc] initWithRequest:url delegate:dd];