I am working on parsing a big xml and storing it into a temporary core data table. My parser didEndElement method looks as follows:
-(void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"reference_number"]) {
[[self pdfDocument] setEducationDocumentReference:currentTextString];
}
if ([elementName isEqualToString:@"name"]) {
[[self pdfDocument] setEducationDocumentName:currentTextString];
}
if ([elementName isEqualToString:@"type"]) {
[[self pdfDocument] setEducationDocumentType:currentTextString];
}
if ([elementName isEqualToString:@"date"]) {
[[self pdfDocument] setEducationDocumentDate:[dateFormatter dateFromString:currentTextString]];
}
if ([elementName isEqualToString:@"url"]) {
[[self pdfDocument] setEducationDocumentURL:currentTextString];
//If I uncomment the following, the app will try finding the previous set
//values without any luck and crash.
//if (![pdfDocument documentExistsInTemporaryTable]) {
// [pdfDocument saveDocumentToTemporaryTable];
//}
}
}
It clearly separates every value as it should be and it should be storing it into the pdfDocument object before saving the object to the temp table, but when I try to access any previously set values for the pdfDocument I get an EXEC_BAD_ACCESS which from what I can see is because it is not finding the value for the previous pdfDocument variables.
I’m sure I’m making a rookie mistake, but can someone enlighten me towards the right direction here?
The problem laid on using the same pointer to the same object. The solution I chose was to have different instances for each value, by simply copying the currentTextString.