Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have translated the <strong>Using NSURLConnection</strong> part of the <a href="http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html" rel="nofollow">URL Loading System Programming Guide</a> using ARC. </p> <pre><code>// // MyConnection.h // #import &lt;Foundation/Foundation.h&gt; @interface MyConnection : NSObject - (void)start; @property NSMutableData *receivedData; @end // // MyConnection.m // #import "MyConnection.h" @implementation MyConnection - (void)start { // Create the request NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; // Create the connection with the request and start loading the data NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; if (theConnection) { // Create the NSMUtableData to fold the received data // ReceivedData is an instance variable declared elsewhere _receivedData = [NSMutableData data]; } } - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { [_receivedData setLength:0]; } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [_receivedData appendData:data]; } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { // Inform the user NSLog(@"Connectionfailed! Error - %@ %@", [error localizedDescription], [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]); } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { // Do something with the data NSLog(@"Succeeded! Recevied %d bytes of data", [_receivedData length]); } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload