November 2013
Beginner
325 pages
9h 47m
English
You can also create an instance of NSData from the contents of a file. Add two lines to your program:
#import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { @autoreleasepool { NSURL *url = [NSURL URLWithString: @"http://www.google.com/images/logos/ps_logo2.png"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; NSError *error; // This method will block until all the data has been fetched NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:&error]; if (!data) { NSLog(@"fetch failed: %@", [error localizedDescription]); return 1; } NSLog(@"The file is %lu bytes", (unsigned long)[data length]); BOOL written = [data writeToFile:@"/tmp/google.png" ...Read now
Unlock full access