Sending a message from Objective-C and getting the return value?
Posted
by Nick Brooks
on Stack Overflow
See other posts from Stack Overflow
or by Nick Brooks
Published on 2010-05-22T15:26:12Z
Indexed on
2010/05/25
8:21 UTC
Read the original article
Hit count: 197
objective-c
|cocoa
I have this code
NSString *tr = [self sendUrl:@"http://google.com/"];
But for some reason 'tr' will remain nil after it is executed. What am I doing wrong?
sendUrl :
- (NSString *)sendUrl:(NSString *) uri {
NSLog(@"Requesting URI 1 ...");
// Prepare URL request to download statuses from Twitter
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:uri]];
NSLog(@"Requesting URI 2 ...");
// Perform request and get JSON back as a NSData object
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSLog(@"Requesting URI 3 ...");
// Get JSON as a NSString from NSData response
NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
NSLog(@"Requesting URI 4 ...");
return json_string;
}
© Stack Overflow or respective owner