Reputation: 922
I am getting an error (well it doesn't shows, just crashes out of app, no info on console) that seems to happen whenever i call the method Iterate from RXML's rootXML:
-(void)valueSearch {
//FIRST CONNECTION
NSString *serverAddress = @"http://www.commix.com.br/clientes/grupoglobo/apple/valor.xml";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:serverAddress]
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval:10];
NSError *requestError;
NSURLResponse *urlResponse = nil;
response = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&requestError];
//SECOND CONNECTION - Just an encapsulated form of the first, since i use it in other parts
// of the code
response = [self requestWithParameters:@"valor.xml"];
//i just uncommented both. but actually only one (connection) runs.
//Creation of the rooXML so i can grab the info i need
RXMLElement *rootXML = [RXMLElement elementFromXMLData:response];
//This array is where i'll keep the info from the files.
//it`s deallocated at the end in dealloc
searchResult = [[NSMutableArray alloc] init];
//This is the culprit. Atleast it seems so, since putting NSLog before and after
//revealed so.
[rootXML iterate:@"valor" usingBlock: ^(RXMLElement *valor) {
NSLog(@"valor: %@", [valor child:@"nome"].text);
[searchResult addObject:[valor child:@"nome"].text];
}];
}
The thing is, when i comment the requestWithParameters
and use the normal non-encapsulated style (//FIRST CONNECTION) i don't get errors. But if i use the second, when the program reaches [rootXML iterate: [...]]
it crashes there without warning.
using RaptureXML: https://github.com/ZaBlanc/RaptureXML
It also happens in another part of the code:
-(void)vehicleSearch {
NSString *path = [[NSBundle mainBundle] pathForResource:@"idArray" ofType:@"plist"];
NSMutableArray *idArray = [[NSMutableArray alloc] initWithContentsOfFile:path];
NSMutableString *serverAddress = (@"http://www.commix.com.br/clientes/grupoglobo/apple/modelo.php?marc=%@",[idArray objectAtIndex:0]);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:serverAddress]
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval:10];
NSError *requestError;
NSURLResponse *urlResponse = nil;
response = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&requestError];
RXMLElement *rootXML = [RXMLElement elementFromXMLData:response];
searchResult = [[NSMutableArray alloc] init];
[rootXML iterate:@"modelo" usingBlock: ^(RXMLElement *modelo) {
NSLog(@"modelo: %@", [modelo child:@"nome"].text);
[searchResult addObject:[modelo child:@"nome"].text];
}];
[idArray release];
}
Happens at the same line [rootXML iterate:]
.
Sorry for leaks and stuff, i'm inexperienced (thats why i'm here), Thanks!
EDIT: ACTUALLY the culprit is the line
NSMutableString *serverAddress = (@"http://www.commix.com.br/clientes/grupoglobo/apple/modelo.php?marc=%@",[idArray objectAtIndex:0]);
if i pass the parameter directly, without variables, it works:
NSMutableString *serverAddress = (@"http://www.commix.com.br/clientes/grupoglobo/apple/modelo.php?marc=4");
it shows correctly.
Upvotes: 1
Views: 597
Reputation: 5966
Are you sure that ,[idArray objectAtIndex:0]
is an NSString?
Try to use
[NSString stringWithFormat:@"http://www.commix.com.br/clientes/grupoglobo/apple/modelo.php?marc=%@",[idArray objectAtIndex:0]];`
Or even
[NSString stringWithFormat:@"http://www.commix.com.br/clientes/grupoglobo/apple/modelo.php?marc=%@",[[idArray objectAtIndex:0]stringValue]];
Upvotes: 1
Reputation: 15213
response = [self requestWithParameters:@"valor.xml"];
if response
is a property use self.response
otherwise you will have memory leak issues.
Upvotes: 1