Programming in objective-c: return string from function objective c on newest questions tagged objective-c – Stack Overflow

I have this function that will get xml through a request operation:

-(id)xmlRequest:(NSString *)xmlurl
{
    AFKissXMLRequestOperation *operation = [AFKissXMLRequestOperation XMLDocumentRequestOperationWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:xmlurl]] success:^(NSURLRequest *request, NSHTTPURLResponse *response, DDXMLDocument *XMLDocument) {
        NSLog(@"XMLDocument: %@", XMLDocument);
    } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, DDXMLDocument *XMLDocument) {
        NSLog(@"Failure!");
    }];
    [operation start];
    return operation;
}

This is my code that calls this function:

Request *http=[[Request alloc] init];
NSString *data=[http xmlRequest:@"http://legalindexes.indoff.com/sitemap.xml"];
NSError *error;
DDXMLDocument *ddDoc=[[DDXMLDocument alloc] initWithXMLString:data options:0 error:&error];
NSArray *xmlItems=[ddDoc nodesForXPath:@"//url" error:&error];
NSMutableArray *returnArray = [[NSMutableArray alloc] initWithCapacity:[xmlItems count]];
for(DDXMLElement* itemElement in xmlItems){
    DDXMLElement *element = [[itemElement nodesForXPath:@"loc" error:&error] objectAtIndex:0];
    NSLog(@"valueasstring %@", element);
    [returnArray addObject:element];
}

I need the xmlRequest to return a string so I can get the XML but the [operation start] creates correct output but I can’t put it in a string. How can I direct the output into a string?

See Answers


source: http://stackoverflow.com/questions/11420358/return-string-from-function-objective-c
Programming in objective-c: programming-in-objective-c



online applications demo