I’m fairly new to objective c but I’m using this code
NSURL *url = [NSURL URLWithString:@"http://xxx.com"];
NSURLRequest *req = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30];
NSURLResponse *resp = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:req returningResponse:&resp error:nil];
NSLog(@"received %???", [data XYZ]);
to try and grab the raw content of a webpage. What would I have to insert instead of XYZ (and obviously ???) so that I could just print the website data. I know that the code pulls some data down because I can use XYZ = length to get the size of the incoming data. If anyone could help, that would be great!
(If anyone could additionally explain how I could have found this in the apple documentation, that would also be really useful)
I assume you mean converting the NSData to a NSString so you can print it?
You should use
to create a string from the data. Note that the encoding is not UTF8 for all websites so it might not produce the correct output always.
You can easily find these methods by browsing the online documentation: http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html