Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If the source code is just “4|3|6” it’s plain text. You can download it using <code>NSURLConnection</code>:</p> <pre><code>NSURL *targetURL = [NSURL URLWithString:@"…"]; NSURLRequest *request = [NSURLRequest requestWithURL:targetURL]; NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; </code></pre> <p>Then you can create a string from the data and parse it:</p> <pre><code>NSString *dataString = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; NSArray *components = [dataString componentsSeparatedByString:@"|"]; [dataString release]; </code></pre> <p>Now you’ll have the components in the resulting array. I’m assuming the data is encoded in ASCII, which might not be the case. And the download is synchronous, which means it will block the current thread. If you’re running the code on the main thread, you might want to dispatch it to a background thread so that you don’t block the UI. But that’s to worry about later, just get it working first.</p> <hr> <p>As for the asynchronous download, I don’t like the asynchronous <code>NSURLConnection</code> interface, as it’s quite a lot of work for what it does. It’s a pity that <code>NSURLConnection</code> does not support blocks. You can find some <code>NSURLConnection</code> extensions with blocks on the web, but that means relying on third-party code, which carries its own possible problems. One easy way to get the download happening in background is this:</p> <pre><code>- (void) performDownload { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSData *downloadedData = /* synchronous NSURLConnection */; [self performSelectorOnMainThread:@selector(downloadDidFinish:) withObject:downloadedData]; [pool drain]; } - (void) downloadDidFinish: (NSData*) data { NSLog(@"Data ready: %@", data); } - (void) startDownload { [self performSelectorInBackground:@selector(performDownload) withObject:nil]; } </code></pre> <p>But you should learn about threading, run loops and autorelease pools before you start using this code, so that you know what you are doing.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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