import Foundation Foundation int main int argc const char argv autorel

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSURL *url = [NSURL URLWithString:@"http://cs608027.vk.me/v608027023/377b/aZifHblF6yo.jpg"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:NULL
error:&error];
if (!data) {
NSLog(@"fetch failed because: %@", [error localizedDescription]);
return 1;
}
NSLog(@"The file is %lu bytes", [data length]);
BOOL written = [data writeToFile:@"/Users/Alex/Desktop/ZapisNSData/picture.jpg"
options:NSDataWritingAtomic
error:&error];
if (!written) {
NSLog(@"Write failed because: %@", [error localizedDescription]);
return 1;
}
NSLog(@"SUCCESS!!!");
}
return 0;
}